ntg-context - mailing list for ConTeXt users
 help / color / mirror / Atom feed
* Processing XML: Header and footer, data manipulation
@ 2019-04-22  5:57 Axel Kielhorn
  2019-04-22  9:40 ` Pablo Rodriguez
  0 siblings, 1 reply; 3+ messages in thread
From: Axel Kielhorn @ 2019-04-22  5:57 UTC (permalink / raw)
  To: ntg-context

[-- Attachment #1: Type: text/plain, Size: 2206 bytes --]

Hello,

Pablo Rodríguez wrote in „From pandoc to ConTeXt“:

„So, if I was able to do this, probably anybody can do it.“

Well, I tried and indeed it isn’t as difficult as i thought.
(Once I learned that an entity must not contain non-ASCII characters.)

Some questions remain:

I want to set page headers based on information I get from the XML:

\startxmlsetups xml:prozess
  \mainlanguage[de]
  \setupheadertexts[\bf\xmltext{#1}{/pnr} \xmltext{#1}{/pname}][\date]
  {\bTABLE
    \setupTABLE[frame=off]
    \setupTABLE[offset=1mm]
    \setupTABLE[c][1][align=right, width=14cm]
    \setupTABLE[c][2][align=left,  width=6cm]
    \setupTABLE[c][3][align=right, width=4cm]
    \bTR \bTD \bfb\xmltext{#1}{/pnr}   \eTD \bTD Version:        \eTD \bTD \bf\xmltext{#1}{/pversion}\eTD \eTR
    \bTR \bTD \bfb\xmltext{#1}{/pname} \eTD \bTD Verantwortlich: \eTD \bTD \bf\xmltext{#1}{/pverantwortlich}\eTD\eTR
  \eTABLE}
  \blank
  \xmlflush{#1}
\stopxmlsetups

This works on the first page (when the document has more than one page) but headers and footers are empty on subsequent pages.

Something (xmlflush?) overwrites my setup.
Any idea how I can fix that?

I want to use xmlconcat here, since there may be more than one docan, but I only get the „, “

\startxmlsetups xml:psoutdoc 
%    \inmargin{\xmltext{#1}{/docan} $\Leftarrow$}  {\bf \xmltext{#1}{/docnr}}\xmlflush{#1}
    \inmargin{\xmlconcat{#1}{/docan}{, } $\Leftarrow$}  {\bf \xmltext{#1}{/docnr}}\xmlflush{#1}
    \xmlsave{#1}{outfile.xml}
    \blank
\stopxmlsetups

I want to write the nodes psindoc and psoutdoc to a separate file.
\xmlsave overwrites the file, is there a way to append to the file? (or append to a buffer and write the buffer?)

\startxmlsetups xml:psindoc
    \inmargin{\xmltext{#1}{/docverantwortlich} $\Rightarrow$} {\bf \xmltext{#1}{/docnr}}\xmlflush{#1}
    \xmlsave{#1}{outfile.xml}
    \blank
\stopxmlsetups

Can I add child notes to #1?

The last two questions probably require LUA, what is a good way to start learning LuaTeX?

I enclosed a small test file.

Greetings Axel

PS: This may result in an article for „Die TeXnische Komödie“.



[-- Attachment #2: prozess-MWE.tex --]
[-- Type: application/octet-stream, Size: 4478 bytes --]

% !TEX TS-program = ConTeXt (LuaTeX 1.0.9)
% Copyright 2019 Axel Kielhorn
% Lizenz: CC-BY-SA 4.0 Unported http://creativecommons.org/licenses/by-sa/4.0/deed.de

\startbuffer[demo]
<prozess>
	<pnr>1.1</pnr>
	<pname>Erster Prozess</pname>
	<pverantwortlich>MKB</pverantwortlich>
	<pversion>1.0</pversion>
	<pschritt>
		<psnr>010</psnr>
		<pskurz>Prozessschritt 1</pskurz>
		<psindoc>
			<docnr>4709</docnr>
			<docname>Werknorm</docname>
			<docverantwortlich>Normausschuss</docverantwortlich>
		</psindoc>		<psindoc>
			<docnr>4710</docnr>
			<docname>Pflichtenheft</docname>
			<docverantwortlich>VT</docverantwortlich>
		</psindoc>
		<psoutdoc>
			<docnr>4711</docnr>
			<docname>Endtermin</docname>
			<docverantwortlich>MKB</docverantwortlich>
			<docan>PL</docan>
		</psoutdoc>
		<aschritt>
			<askurz>Arbeitsschritt 1</askurz>
			<aslang>Dieser Arbeitsschritt dauert etwas länger.
			Es muss doch möglich sein, die gesamte Textbreite auszunutzen, um einen Zeilenumbruch zu erzeugen.
			Noch etwas mehr, damit das nach Arbeit aussieht.</aslang>
			<asverantwortlich>MA MKB</asverantwortlich>
		</aschritt>
		<eschritt>
			<eskurz>Ergebnis 1</eskurz>
		</eschritt>
		<aschritt>
			<askurz>Arbeitsschritt 2</askurz>
			<asverantwortlich>MA MKB</asverantwortlich>
		</aschritt>
		<eschritt>
			<eskurz>Ergebnis 2</eskurz>
		</eschritt>
	</pschritt>
	<pschritt>
		<psnr>020</psnr>
		<pskurz>Prozessschritt 1</pskurz>
		<pslang>Prozessschritt lang</pslang>
		<psindoc>
			<docnr>4710</docnr>
			<docname>Pflichtenheft</docname>
			<docverantwortlich>VT</docverantwortlich>
		</psindoc>
		<psoutdoc>
			<docnr>4711</docnr>
			<docname>Endtermin</docname>
			<docverantwortlich>MKB</docverantwortlich>
			<docan>PL</docan>
			<docan>GL</docan>
		</psoutdoc>
		<aschritt>
			<askurz>Arbeitsschritt 1</askurz>
			<asverantwortlich>MA MKB</asverantwortlich>
		</aschritt>
		<eschritt>
			<eskurz>Ergebnis 1</eskurz>
		</eschritt>
		<aschritt>
			<askurz>Arbeitsschritt 2</askurz>
			<asverantwortlich>MA MKB</asverantwortlich>
		</aschritt>
		<eschritt>
			<eskurz>Ergebnis 2</eskurz>
		</eschritt>
	</pschritt>

</prozess>
\stopbuffer

\language[de]
\mainlanguage[de]
\setbreakpoints[compound]

\setuphyphenation[method=expanded]

\setuppapersize [A4,landscape][A4,landscape]
\setuplayout    [width=middle,  backspace=2in, cutspace=1in, leftmargin=1.5in,
                 height=middle, topspace=1in, bottomspace=1in]

\setuppagenumbering[location={footer,right}]

\startxmlsetups xml:prozessb
    \xmlsetsetup{#1}{*}{-}
    \xmlsetsetup{#1}{prozess|pschritt|psindoc|psoutdoc|docname|aschritt|eschritt}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:prozessb}

\startxmlsetups xml:prozess
  \mainlanguage[de]
  \setupheadertexts[\bf\xmltext{#1}{/pnr} \xmltext{#1}{/pname}][\date]
  {\bTABLE
    \setupTABLE[frame=off]
    \setupTABLE[offset=1mm]
    \setupTABLE[c][1][align=right, width=14cm]
    \setupTABLE[c][2][align=left,  width=6cm]
    \setupTABLE[c][3][align=right, width=4cm]
    \bTR \bTD \bfb\xmltext{#1}{/pnr}   \eTD \bTD Version:        \eTD \bTD \bf\xmltext{#1}{/pversion}\eTD \eTR
    \bTR \bTD \bfb\xmltext{#1}{/pname} \eTD \bTD Verantwortlich: \eTD \bTD \bf\xmltext{#1}{/pverantwortlich}\eTD\eTR
  \eTABLE}
  \blank
  \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:pschritt
    \inmargin{\bf \xmltext{#1}{../pnr}.\xmltext{#1}{/psnr}}
    {\bf \xmldoifelse{#1}{/pslang}{\xmltext{#1}{/pslang}}{\xmltext{#1}{/pskurz}}}
    \blank
    \xmlflush{#1}
    \blank
\stopxmlsetups

\startxmlsetups xml:psindoc
    \inmargin{\xmltext{#1}{/docverantwortlich} $\Rightarrow$} {\bf \xmltext{#1}{/docnr}}\xmlflush{#1}
    \blank
\stopxmlsetups

\startxmlsetups xml:psoutdoc
    \inmargin{\xmltext{#1}{/docan} $\Leftarrow$}  {\bf \xmltext{#1}{/docnr}}\xmlflush{#1}
    \blank
\stopxmlsetups

\startxmlsetups xml:docname
    \xmlflush{#1}
\stopxmlsetups

\startxmlsetups xml:aschritt
    \color[darkgreen]{
    \inmargin{\color[darkgreen]{\xmltext{#1}{/asverantwortlich}}}
    {\xmldoifelse{#1}{/aslang}{\xmltext{#1}{/aslang}}{\xmltext{#1}{/askurz}}}
    \xmlflush{#1}
    }
    \blank
\stopxmlsetups

\startxmlsetups xml:eschritt
    \color[red]{
    {\xmldoifelse{#1}{/eslang}{\xmltext{#1}{/eslang}}{\xmltext{#1}{/eskurz}}}
    \xmlflush{#1}}
    \blank
\stopxmlsetups

\starttext
	\xmlprocessbuffer{main}{demo}{}
\stoptext

[-- Attachment #3: Type: text/plain, Size: 493 bytes --]

___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Processing XML: Header and footer, data manipulation
  2019-04-22  5:57 Processing XML: Header and footer, data manipulation Axel Kielhorn
@ 2019-04-22  9:40 ` Pablo Rodriguez
  2019-04-22 15:50   ` Axel Kielhorn
  0 siblings, 1 reply; 3+ messages in thread
From: Pablo Rodriguez @ 2019-04-22  9:40 UTC (permalink / raw)
  To: ntg-context

On 4/22/19 7:57 AM, Axel Kielhorn wrote:
> [...]
> Some questions remain:

Hi Axel,

I have some questions about your source file:

  \startxmlsetups xml:prozess
     \mainlanguage[de]

If this is hardcoded (I mean, you don’t read it from any XML code), I
would avoid setting the \mainlanguage here.

And you already set it in lines 82-83:

  \language[de]
  \mainlanguage[de]

BTW, is there any reason to set both \language and \mainlanguage?
(\mainlanguage should be enough.)

> I want to set page headers based on information I get from the XML:
>
> \startxmlsetups xml:prozess
>   \setupheadertexts[\bf\xmltext{#1}{/pnr} \xmltext{#1}{/pname}][\date]
>
> This works on the first page (when the document has more than one
> page) but headers and footers are empty on subsequent pages.
>
> Something (xmlflush?) overwrites my setup.
> Any idea how I can fix that?

I have a workaround for that:

  \title{\xmltext{#1}{/pnr} \xmltext{#1}{/pname}}

And in your preamble:

  \setupheadertexts[title][\date]
  \setuphead[title]
    [placehead=empty,
     before=,
     after=,
     page=,]

> I want to use xmlconcat here, since there may be more than one docan, but I only get the „, “
>
> \startxmlsetups xml:psoutdoc
> %    \inmargin{\xmltext{#1}{/docan} $\Leftarrow$}  {\bf \xmltext{#1}{/docnr}}\xmlflush{#1}
>     \inmargin{\xmlconcat{#1}{/docan}{, } $\Leftarrow$}  {\bf \xmltext{#1}{/docnr}}\xmlflush{#1}
>     \xmlsave{#1}{outfile.xml}
>     \blank
> \stopxmlsetups

I would avoid using:

  \startxmlsetups xml:docname
    \xmlflush{#1}
  \stopxmlsetups

instead of "\xmltext{#1}{/docname}" in the proper places.

You need to add to get proper content:

  \startxmlsetups xml:docan
    \xmlflush{#1}
  \stopxmlsetups

I would replace docname with docan in both places (xmlsetsetup and its
proper \starxmlsetups).

BTW, what should be child notes to #1? An special lpath or what?

Just in case it helps,

Pablo
--
http://www.ousia.tk
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Processing XML: Header and footer, data manipulation
  2019-04-22  9:40 ` Pablo Rodriguez
@ 2019-04-22 15:50   ` Axel Kielhorn
  0 siblings, 0 replies; 3+ messages in thread
From: Axel Kielhorn @ 2019-04-22 15:50 UTC (permalink / raw)
  To: ntg-context


> Am 22.04.2019 um 11:40 schrieb Pablo Rodriguez <oinos@gmx.es>:
> 
> I have some questions about your source file:
> 
>  \startxmlsetups xml:prozess
>     \mainlanguage[de]
> 
> If this is hardcoded (I mean, you don’t read it from any XML code), I
> would avoid setting the \mainlanguage here.
> 
> And you already set it in lines 82-83:
> 
>  \language[de]
>  \mainlanguage[de]
> 
> BTW, is there any reason to set both \language and \mainlanguage?
> (\mainlanguage should be enough.)

A leftover from merging two documents.
Once should be sufficient.
I’m not sure if it was a good idea to use german names for the elements.
Using english names and making the language configurable may be the next step.


>> I want to set page headers based on information I get from the XML:
>> 
>> \startxmlsetups xml:prozess
>>  \setupheadertexts[\bf\xmltext{#1}{/pnr} \xmltext{#1}{/pname}][\date]
>> 
>> This works on the first page (when the document has more than one
>> page) but headers and footers are empty on subsequent pages.
>> 
>> Something (xmlflush?) overwrites my setup.
>> Any idea how I can fix that?
> 
> I have a workaround for that:
> 
>  \title{\xmltext{#1}{/pnr} \xmltext{#1}{/pname}}
> 
> And in your preamble:
> 
>  \setupheadertexts[title][\date]
>  \setuphead[title]
>    [placehead=empty,
>     before=,
>     after=,
>     page=,]
> 
>> I want to use xmlconcat here, since there may be more than one docan, but I only get the „, “
>> 
>> \startxmlsetups xml:psoutdoc
>> %    \inmargin{\xmltext{#1}{/docan} $\Leftarrow$}  {\bf \xmltext{#1}{/docnr}}\xmlflush{#1}
>>    \inmargin{\xmlconcat{#1}{/docan}{, } $\Leftarrow$}  {\bf \xmltext{#1}{/docnr}}\xmlflush{#1}
>>    \xmlsave{#1}{outfile.xml}
>>    \blank
>> \stopxmlsetups
> 
> I would avoid using:
> 
>  \startxmlsetups xml:docname
>    \xmlflush{#1}
>  \stopxmlsetups
> 
> instead of "\xmltext{#1}{/docname}" in the proper places.

Right, I startet out \xmlflush{}ing everything and turned it into \xmltext later.
I missed this one.

> You need to add to get proper content:
> 
>  \startxmlsetups xml:docan
>    \xmlflush{#1}
>  \stopxmlsetups
> 
> I would replace docname with docan in both places (xmlsetsetup and its
> proper \starxmlsetups).

Great, it works now.

> BTW, what should be child notes to #1? An special lpath or what?

I want to add
<docan>\xmltext{#1}{../../pverantwortlich}</docan>
to psindoc

And
<docverantwortlich>\xmltext{#1}{../../pverantwortlich}</docverantwortlich>
to psoutdoc

before writing the ps[in|out]doc to an extra file.

But thinking about it, it may be easier to load a <doclist></doclist> tree from a separate file
and add / edit the doc entries based on the <docnr>.
(<docnr>s are unique.)

This part isn’t even in my head now.

> Just in case it helps,

It did, thanks!
Right now the document does what I wanted to do in ConTeXt.
I’m tempted to write the remaining functions in lua instead of python.

Still a lot to learn ahead.

Greetings Axel



___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2019-04-22 15:50 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-22  5:57 Processing XML: Header and footer, data manipulation Axel Kielhorn
2019-04-22  9:40 ` Pablo Rodriguez
2019-04-22 15:50   ` Axel Kielhorn

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).