Re: [NTG-context] Processing XML: Header and footer, data manipulation

2019-04-22 Thread Axel Kielhorn

> Am 22.04.2019 um 11:40 schrieb Pablo Rodriguez :
> 
> 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
\xmltext{#1}{../../pverantwortlich}
to psindoc

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

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

But thinking about it, it may be easier to load a  tree from 
a separate file
and add / edit the doc entries based on the .
(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
___


Re: [NTG-context] Processing XML: Header and footer, data manipulation

2019-04-22 Thread Pablo Rodriguez
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
___


[NTG-context] Processing XML: Header and footer, data manipulation

2019-04-22 Thread Axel Kielhorn
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“.




prozess-MWE.tex
Description: Binary data
___
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
___


Re: [NTG-context] Processing XML file inside a zip file

2019-01-10 Thread Aditya Mahajan

On Fri, 11 Jan 2019, Henri Menke wrote:


On 11/01/19 4:42 PM, Aditya Mahajan wrote:

Hi,

Is it possible to process an XML file inside a zip file without unzipping?

In particular, I have a program that generates zip files which look like
this:

The file `filename.zip` contains:
- filename.xml - file_hash1.png
- file_hash2.png
etc.

Where `filename.xml` (the name matches the basename of the zip file) is
the main xml file and the `file_hash1.png` etc are png files that are
referred to inside the xml file.

If I unzip the file and add

\setupexternalfigures[directory={path-to-unzipped-folder]

then, I have an \startxmlsetups .. \stopxmlsetups environment that
correctly typesets the xml file. I believe that I have seen Hans post
snippets of code that suggest that context can directly read from a zip
file. So, I am wondering if there is a way that I can just call

context --magic-flags filename.zip


You can directly typeset ePub files which is just zipped XML.  There is
a script in mtxrun for it:

   context --ctx=x-epub.ctx yourfile.epub

Documented in: http://www.pragma-ade.nl/general/manuals/hybrid.pdf


Thanks. But I could not find `x-epub.ctx` file in the standalone 
distribution.


Aditya
___
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
___

Re: [NTG-context] Processing XML file inside a zip file

2019-01-10 Thread Henri Menke
On 11/01/19 4:42 PM, Aditya Mahajan wrote:
> Hi,
> 
> Is it possible to process an XML file inside a zip file without unzipping?
> 
> In particular, I have a program that generates zip files which look like
> this:
> 
> The file `filename.zip` contains:
> - filename.xml - file_hash1.png
> - file_hash2.png
> etc.
> 
> Where `filename.xml` (the name matches the basename of the zip file) is
> the main xml file and the `file_hash1.png` etc are png files that are
> referred to inside the xml file.
> 
> If I unzip the file and add
> 
> \setupexternalfigures[directory={path-to-unzipped-folder]
> 
> then, I have an \startxmlsetups .. \stopxmlsetups environment that
> correctly typesets the xml file. I believe that I have seen Hans post
> snippets of code that suggest that context can directly read from a zip
> file. So, I am wondering if there is a way that I can just call
> 
> context --magic-flags filename.zip

You can directly typeset ePub files which is just zipped XML.  There is
a script in mtxrun for it:

context --ctx=x-epub.ctx yourfile.epub

Documented in: http://www.pragma-ade.nl/general/manuals/hybrid.pdf

> 
> and obtain the correct output.
> 
> Thanks,
> Aditya
> ___
> 
> 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
> ___

___
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
___

[NTG-context] Processing XML file inside a zip file

2019-01-10 Thread Aditya Mahajan

Hi,

Is it possible to process an XML file inside a zip file without unzipping?

In particular, I have a program that generates zip files which look like 
this:


The file `filename.zip` contains:
- filename.xml 
- file_hash1.png

- file_hash2.png
etc.

Where `filename.xml` (the name matches the basename of the zip file) is 
the main xml file and the `file_hash1.png` etc are png files that are 
referred to inside the xml file.


If I unzip the file and add

\setupexternalfigures[directory={path-to-unzipped-folder]

then, I have an \startxmlsetups .. \stopxmlsetups environment that 
correctly typesets the xml file. I believe that I have seen Hans post 
snippets of code that suggest that context can directly read from a zip 
file. So, I am wondering if there is a way that I can just call


context --magic-flags filename.zip

and obtain the correct output.

Thanks,
Aditya
___
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
___

Re: [NTG-context] processing xml with lua

2013-03-05 Thread Thomas A. Schmitz

Hi,

may I ask another question about my new favorite topic? No? Anyway: here 
comes. While processing xml, I would like to store the content of a node 
in a lua table and retrieve it later. The example is silly, but 
demonstrates my problem. Is there a way to have ConTeXt process and 
typeset the value in lines 3 and 4? As you can see, it typesets the raw 
xml instead of processing it. (I suspect I'm still a bit lost regarding 
the difference between xml... and lxml... functions, but I couldn't hit 
the right combination here).


Thanks, and all best

Thomas

\startbuffer[test]
a
  bcFruit/c deApple/e/d/b
  bcVegetable/c dqCarot/q/d/b
  bcFruit/c/b
  bcVegetable/c/b
/a
\stopbuffer

\startxmlsetups xml:testsetups
\xmlsetsetup{\xmldocument}{a|b|c|d}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:testsetups}

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

\startxmlsetups xml:b
\xmlfunction{#1}{lookup} \par
\stopxmlsetups

\startxmlsetups xml:e
{\bgroup\em \xmlflush{#1}\egroup}
\stopxmlsetups

\startxmlsetups xml:q
\quotation{\xmlflush{#1}}
\stopxmlsetups

\startluacode
lookuptable = { }
function xml.functions.lookup(t)
  mytype = xml.text(t, c)
  myvalue = xml.text(t, d)
  if not lookuptable[mytype] then
context(New Type: ) context(mytype) context(; its value is: ) 
lxml.text(t, d)

lookuptable[mytype] = mytype ..  =  .. myvalue
  else
context(This Type is already known: ) context(lookuptable[mytype])
  end
end
\stopluacode

\starttext
\xmlprocessbuffer{main}{test}{}

\stoptext
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml with lua

2013-03-05 Thread Hans Hagen

On 3/5/2013 9:47 AM, Thomas A. Schmitz wrote:

Hi,

may I ask another question about my new favorite topic? No? Anyway: here
comes. While processing xml, I would like to store the content of a node
in a lua table and retrieve it later. The example is silly, but
demonstrates my problem. Is there a way to have ConTeXt process and
typeset the value in lines 3 and 4? As you can see, it typesets the raw
xml instead of processing it. (I suspect I'm still a bit lost regarding
the difference between xml... and lxml... functions, but I couldn't hit
the right combination here).


lookuptable[mytype] = mytype ..  =  .. myvalue
inspect(lookuptable)

the .. triggers a tostring on myvalue which in turn serializes the xml

lookuptable[mytype] = { mytype = myvalue }

would keep myvalue as xml node



Thanks, and all best

Thomas

\startbuffer[test]
a
   bcFruit/c deApple/e/d/b
   bcVegetable/c dqCarot/q/d/b
   bcFruit/c/b
   bcVegetable/c/b
/a
\stopbuffer

\startxmlsetups xml:testsetups
 \xmlsetsetup{\xmldocument}{a|b|c|d}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:testsetups}

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

\startxmlsetups xml:b
 \xmlfunction{#1}{lookup} \par
\stopxmlsetups

\startxmlsetups xml:e
 {\bgroup\em \xmlflush{#1}\egroup}
\stopxmlsetups

\startxmlsetups xml:q
 \quotation{\xmlflush{#1}}
\stopxmlsetups

\startluacode
lookuptable = { }
function xml.functions.lookup(t)
   mytype = xml.text(t, c)
   myvalue = xml.text(t, d)
   if not lookuptable[mytype] then
 context(New Type: ) context(mytype) context(; its value is: )
lxml.text(t, d)
 lookuptable[mytype] = mytype ..  =  .. myvalue
   else
 context(This Type is already known: ) context(lookuptable[mytype])
   end
end
\stopluacode

\starttext
\xmlprocessbuffer{main}{test}{}

\stoptext
___

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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___




--

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml with lua

2013-03-05 Thread Thomas A. Schmitz

On 03/05/2013 09:58 AM, Hans Hagen wrote:

 lookuptable[mytype] = mytype ..  =  .. myvalue
 inspect(lookuptable)

the .. triggers a tostring on myvalue which in turn serializes the xml

 lookuptable[mytype] = { mytype = myvalue }

would keep myvalue as xml node


Hans, thanks a lot, the explanation makes sense, but your suggestion is 
not yet clear enough for me: how would I then process the node?


context(lookuptable[mytype][mytype])

gives again the serialized xml.

Thomas
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml with lua

2013-03-05 Thread Hans Hagen

On 3/5/2013 10:16 AM, Thomas A. Schmitz wrote:

On 03/05/2013 09:58 AM, Hans Hagen wrote:

 lookuptable[mytype] = mytype ..  =  .. myvalue
 inspect(lookuptable)

the .. triggers a tostring on myvalue which in turn serializes the xml

 lookuptable[mytype] = { mytype = myvalue }

would keep myvalue as xml node


Hans, thanks a lot, the explanation makes sense, but your suggestion is
not yet clear enough for me: how would I then process the node?

context(lookuptable[mytype][mytype])

gives again the serialized xml.


\startluacode
local lookuptable = { }
function xml.functions.lookup(t)
local mytype  = xml.text(t, c)
local myvalue = lookuptable[mytype]
if not myvalue then
myvalue = xml.first(t, d)
lookuptable[mytype] = myvalue
context(registered: )
else
context(reused: )
end
-- each found node gets an id
lxml.flush(lxml.id(myvalue))
context( or )
-- in tex mode a to-tex serializer is the default
xml.cprint(myvalue)
end
\stopluacode

One place to look for tricks is in x-mathml.mkiv / lua (I know, I should 
finish that manual).


Hans

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml with lua

2013-03-05 Thread Thomas A. Schmitz

On 03/05/2013 11:11 AM, Hans Hagen wrote:

\startluacode
local lookuptable = { }
function xml.functions.lookup(t)
 local mytype  = xml.text(t, c)
 local myvalue = lookuptable[mytype]
 if not myvalue then
 myvalue = xml.first(t, d)
 lookuptable[mytype] = myvalue
 context(registered: )
 else
 context(reused: )
 end
 -- each found node gets an id
 lxml.flush(lxml.id(myvalue))
 context( or )
 -- in tex mode a to-tex serializer is the default
 xml.cprint(myvalue)
end
\stopluacode

One place to look for tricks is in x-mathml.mkiv / lua (I know, I should
finish that manual).

Hans


Beautiful! Thanks a lot, that's just what I needed. And yes, in the 
medium-to-long run, finishing the manual will save you from being 
pestered with my questions... :-)


Thomas
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


[NTG-context] processing xml with lua

2013-02-26 Thread Schmitz Thomas A.
Hi all,

one of my favorite topics… Here is a minimal example which shows something that 
I don't understand: when I process the subsection with the lua code, I want to 
get the value of the current section's label attribute in xml.attribute(r, 
../../section, label, X). So i was expecting that lua would go up 
(../../) and fetch the current section's label. But if you run the example, you 
see that it actually always gets the first section's label (value is always 1). 
How can I get the current section's label with a lua function?

THanks and all best

Thomas

\startbuffer[test]
chapter
  section label=1
subsection label=1
  content
text 1.1
  /content
/subsection
  /section
  section label=3
subsection label=1
  content
text 3.1
  /content
/subsection
subsection label=5
  content
text 3.5
  /content
/subsection
  /section
/chapter
\stopbuffer

\startxmlsetups xml:testsetups
\xmlsetsetup{\xmldocument}{chapter|section|subsection|content}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:testsetups}

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

\startxmlsetups xml:section
\xmlflush{#1} \par
\stopxmlsetups

\startxmlsetups xml:subsection
\xmlfunction{#1}{test}
\stopxmlsetups

\startluacode
outfile = io.open('temp.tmp', 'w')
function xml.functions.test(r)
  content = xml.text(r, content)
  section = xml.attribute(r, ../../section, label, X)
  context(This ) context(content) context( is in section ) context(section)
end
\stopluacode

\starttext
\xmlprocessbuffer{main}{test}{}

\enabletrackers[context.trace]

\xmlshow{main}
\stoptext

___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml with lua

2013-02-26 Thread Hans Hagen

On 2/26/2013 1:23 PM, Schmitz Thomas A. wrote:

Hi all,

one of my favorite topics… Here is a minimal example which shows something that I don't understand: when I process the 
subsection with the lua code, I want to get the value of the current section's label attribute in 
xml.attribute(r, ../../section, label, X). So i was expecting that lua would go up 
(../../) and fetch the current section's label. But if you run the example, you see that it actually always gets the 
first section's label (value is always 1). How can I get the current section's label with a lua function?


you go up to the parent of sections which to far up, try:

  section = xml.attribute(r, .., label, X)

or

  section = xml.filter(r, ../attribute(label))


THanks and all best

Thomas

\startbuffer[test]
chapter
   section label=1
 subsection label=1
   content
 text 1.1
   /content
 /subsection
   /section
   section label=3
 subsection label=1
   content
 text 3.1
   /content
 /subsection
 subsection label=5
   content
 text 3.5
   /content
 /subsection
   /section
/chapter
\stopbuffer

\startxmlsetups xml:testsetups
\xmlsetsetup{\xmldocument}{chapter|section|subsection|content}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:testsetups}

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

\startxmlsetups xml:section
\xmlflush{#1} \par
\stopxmlsetups

\startxmlsetups xml:subsection
\xmlfunction{#1}{test}
\stopxmlsetups

\startluacode
outfile = io.open('temp.tmp', 'w')
function xml.functions.test(r)
   content = xml.text(r, content)
   section = xml.attribute(r, ../../section, label, X)
   context(This ) context(content) context( is in section ) context(section)
end
\stopluacode

\starttext
\xmlprocessbuffer{main}{test}{}

\enabletrackers[context.trace]

\xmlshow{main}
\stoptext

___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___




--

-
  Hans Hagen | PRAGMA ADE
  Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
tel: 038 477 53 69 | voip: 087 875 68 74 | www.pragma-ade.com
 | www.pragma-pod.nl
-
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml with lua

2013-02-26 Thread Schmitz Thomas A.

On Feb 26, 2013, at 1:54 PM, Hans Hagen pra...@wxs.nl wrote:

 you go up to the parent of sections which to far up, try:
 
  section = xml.attribute(r, .., label, X)
 
 or
 
  section = xml.filter(r, ../attribute(label))
 
 

Mojca, Hans,

thanks, that is exactly right! I wasn't too sure about ../../section, but now 
it makes sense. I have to study xpath a bit more, I guess.

All best

Thomas
___
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://tex.aanhet.net
archive  : http://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml

2008-05-07 Thread Roger Mason
Hello Wolfgang,

Wolfgang Schuster [EMAIL PROTECTED] writes:

 take a look into the XML manual, the magazine is a little bit special and
 not the best starting point.

 http://www.pragma-ade.com/show-man-15.htm

Thank you _very_ much.  That was just what I needed: to quote the
example I just ran: What a happy end to a small story!.  Context is
pretty amazing.

Cheers,
Roger
___
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


[NTG-context] processing xml

2008-05-06 Thread Roger Mason
Hello,

I have a document converted from rtf to xml that I'd like to attempt
to typeset using Context.

As a starting point I tried to follow the procedure in a document from
the wiki: mag-0008-1.pdf Dealing with XML.  Having copied the first
example document and stylesheet from that article and generated
sample-1.fx, I run:

texexec --pdf --use=fx --xml sample-1.fx

but it ends with:

(/usr/local/context_minimal/tex/texmf-local/tex/context/base/spec-fdf.tex
(/usr/local/context_minimal/tex/texmf-local/tex/context/base/spec-fdf.mkii))
specials: fdf loaded
)
specials: fdf,tpd loaded
system  : module fx not found
)
systems : system commands are enabled
)
*

I installed the minimal today from the wiki to be up to date before
posting.

Probably something has changed in the four years since mag-0008-1.pdf
was written.  If some kind soul would point me in the right direction
I'll be very grateful.

Roger
___
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml in mkiv

2008-03-18 Thread Thomas A. Schmitz

On Mar 17, 2008, at 2:04 PM, Taco Hoekwater wrote:

 It is a bug in luatex, but not an easy one to fix. The simplest
 workaround (for now) is to patch core-job.lua.

 Best wishes,
 Taco


 --- core-job.lua~   2008-02-13 12:01:06.0 +0100
 +++ core-job.lua2008-03-17 14:02:12.0 +0100
 @@ -64,7 +64,7 @@
  function commands.processfile(name,maxreadlevel)
name = find_file(name,maxreadlevel)
if name ~=  then
 -tex.sprint(tex.ctxcatcodes,string.format(\\input %s\ 
 \relax,name))
 +tex.print(tex.ctxcatcodes,string.format(\\input %s\ 
 \relax,name))
end
  end



Thanks Taco! I was away from my computer yesterday, but will try that  
today.

All best

Thomas
___
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml in mkiv

2008-03-17 Thread Thomas A. Schmitz

On Mar 16, 2008, at 6:16 PM, Hans Hagen wrote:

 indeed ther eis something weird, but it may as well be something in
 lautex itself, so taco has to look into it too

 what happens is:

 \def\processXMLfilegrouped#1{{\enableXML\processfile{#1}\relax 
 \ifmmode\else\par\fi}}

 it looks like the new catcode regime lags one line behind here

Glad to know it wasn't just me being stupid... So I will continue to  
try  my hand at the new mkiv mechanism.

All best

Thomas
___
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml in mkiv

2008-03-17 Thread Taco Hoekwater


Thomas A. Schmitz wrote:
 On Mar 16, 2008, at 6:16 PM, Hans Hagen wrote:
 
 indeed ther eis something weird, but it may as well be something in
 lautex itself, so taco has to look into it too

 what happens is:

 \def\processXMLfilegrouped#1{{\enableXML\processfile{#1}\relax 
 \ifmmode\else\par\fi}}

 it looks like the new catcode regime lags one line behind here
 
 Glad to know it wasn't just me being stupid... So I will continue to  
 try  my hand at the new mkiv mechanism.

It is a bug in luatex, but not an easy one to fix. The simplest
workaround (for now) is to patch core-job.lua.

Best wishes,
Taco


--- core-job.lua~   2008-02-13 12:01:06.0 +0100
+++ core-job.lua2008-03-17 14:02:12.0 +0100
@@ -64,7 +64,7 @@
  function commands.processfile(name,maxreadlevel)
name = find_file(name,maxreadlevel)
if name ~=  then
-tex.sprint(tex.ctxcatcodes,string.format(\\input %s\\relax,name))
+tex.print(tex.ctxcatcodes,string.format(\\input %s\\relax,name))
end
  end



___
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


[NTG-context] processing xml in mkiv

2008-03-16 Thread Thomas A. Schmitz
Hi all,

xml processing is about the last part of my ConTeXt stuff where I  
haven't been able to switch to mkiv; I just can't get my head around  
it... 2 questions:

1. When I try to process a xml-file with my old (mkii) environments,  
the output looks OK, but I always get a first page with the xml  
version declaration

?xml version=1.0 encoding=utf-8?

Is this a bug or a feature? Is there anything I can do to prevent it?

2. I'm really lost with the new xml mechanism. My first problem: In a  
message from September last year, Hans explained that the command to  
process xml files is:

 The regular definitions still work but processing a file is done
 differently:

 \xmlprocess{id}{filename}{optional initialization setup}

I used to have environments with which to typeset a bunch of files.  
How can  this be ported to the new mechanism, which appears to expect  
a filename?

Sorry if these are very basic problems, but I'm probably a bit obtuse  
here.

All best

Thomas
___
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml in mkiv

2008-03-16 Thread Wolfgang Schuster
On Sun, 16 Mar 2008 11:29:49 +0100
Thomas A. Schmitz [EMAIL PROTECTED] wrote:

 Hi all,
 
 xml processing is about the last part of my ConTeXt stuff where I  
 haven't been able to switch to mkiv; I just can't get my head around  
 it... 2 questions:
 
 1. When I try to process a xml-file with my old (mkii) environments,  
 the output looks OK, but I always get a first page with the xml  
 version declaration
 
 ?xml version=1.0 encoding=utf-8?
 
 Is this a bug or a feature? Is there anything I can do to prevent it?

Can you post a example, I never saw such a effect in my test files.

 2. I'm really lost with the new xml mechanism. My first problem: In a  
 message from September last year, Hans explained that the command to  
 process xml files is:
 
  The regular definitions still work but processing a file is done
  differently:
 
  \xmlprocess{id}{filename}{optional initialization setup}
 
 I used to have environments with which to typeset a bunch of files.  
 How can  this be ported to the new mechanism, which appears to expect  
 a filename?

\xmlprocess{main}{filename.xml}{} works for me.

 Sorry if these are very basic problems, but I'm probably a bit obtuse  
 here.

You don't have to use new xml mechanism form MkIV, the old code could
be used without problems. The advantage of the new code is direct
access to elements in the tree (you could use xml files as database)
and the option to read from zip files.

Wolfgang
___
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml in mkiv

2008-03-16 Thread Thomas A. Schmitz

On Mar 16, 2008, at 12:04 PM, Wolfgang Schuster wrote:

 On Sun, 16 Mar 2008 11:29:49 +0100
 Thomas A. Schmitz [EMAIL PROTECTED] wrote:

 Hi all,

 xml processing is about the last part of my ConTeXt stuff where I
 haven't been able to switch to mkiv; I just can't get my head around
 it... 2 questions:

 1. When I try to process a xml-file with my old (mkii) environments,
 the output looks OK, but I always get a first page with the xml
 version declaration

 ?xml version=1.0 encoding=utf-8?

 Is this a bug or a feature? Is there anything I can do to prevent it?

 Can you post a example, I never saw such a effect in my test files.

Hi Wolfgang,

OK, here is a minimal example:

file test.xml:

?xml version=1.0 encoding=utf-8?
!DOCTYPE test [
!ELEMENT document   (section)
!ELEMENT section(#PCDATA)
]

document
   section title=First
 pThis is quotationan/quotation xml file./p
   /section
/document

file testenvironment.tex

\usemodule[xtag-ent]

\defineXMLenvironment[document]
  {\starttext}
  {\stoptext}

\defineXMLenvironment[section]
  {\section{\XMLpar{section}{title}{}}}
  {}

\defineXMLenvironment[quotation]
  {\quotation\bgroup}
  {\egroup}


When I process with mkii, I get the expected output. Processing with

texexec --lua --env=testenvironment test.xml

gives me the first line (here it's not an entire page) I described!



 2. I'm really lost with the new xml mechanism. My first problem: In a
 message from September last year, Hans explained that the command to
 process xml files is:

 The regular definitions still work but processing a file is done
 differently:

\xmlprocess{id}{filename}{optional initialization setup}

 I used to have environments with which to typeset a bunch of files.
 How can  this be ported to the new mechanism, which appears to expect
 a filename?

 \xmlprocess{main}{filename.xml}{} works for me.

I tried to translate this into the new mechanism and thought it  
should read like so:

\startxmlsetups xml:mysetups
\xmlsetsetup{\xmldocument}{text:p|section|quotation}{xml:*}
\stopxmlsetups

\xmlregistersetup{xml:mysetups}

\startxmlsetups xml:p
\xmlflush{#1}\endgraf
\stopxmlsetups

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

\startxmlsetups xml:section
\section{\xmlatt{#1}{section}{title}}
\stopxmlsetups

\starttext
\xmlprocess{main}{test.xml}{}
\stoptext

But then, I only get invalid xml file in the output.



 Sorry if these are very basic problems, but I'm probably a bit obtuse
 here.

 You don't have to use new xml mechanism form MkIV, the old code could
 be used without problems. The advantage of the new code is direct
 access to elements in the tree (you could use xml files as database)
 and the option to read from zip files.

 Wolfgang

OK, I'll keep that in mind. Thanks for your help, Wolfgang!

Thomas
___
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml in mkiv

2008-03-16 Thread Wolfgang Schuster
 OK, here is a minimal example:
 
 file test.xml:
 
 ?xml version=1.0 encoding=utf-8?
 !DOCTYPE test [
 !ELEMENT document   (section)
 !ELEMENT section(#PCDATA)
 ]
 
 document
section title=First
  pThis is quotationan/quotation xml file./p
/section
 /document
 
 file testenvironment.tex
 
 \usemodule[xtag-ent]
 
 \defineXMLenvironment[document]
   {\starttext}
   {\stoptext}
 
 \defineXMLenvironment[section]
   {\section{\XMLpar{section}{title}{}}}
   {}
 
 \defineXMLenvironment[quotation]
   {\quotation\bgroup}
   {\egroup}
 
 
 When I process with mkii, I get the expected output. Processing with
 
 texexec --lua --env=testenvironment test.xml
 
 gives me the first line (here it's not an entire page) I described!

This seems like a bug to me. This did only happen with the content in
the first line because I inserted a empty first line at the begin of
the line the xml header disappeared from the pdf, could be related to
a wrong catcode for the  at the beginning of the line.

  2. I'm really lost with the new xml mechanism. My first problem: In a
  message from September last year, Hans explained that the command to
  process xml files is:
 
  The regular definitions still work but processing a file is done
  differently:
 
 \xmlprocess{id}{filename}{optional initialization setup}
 
  I used to have environments with which to typeset a bunch of files.
  How can  this be ported to the new mechanism, which appears to expect
  a filename?
 
  \xmlprocess{main}{filename.xml}{} works for me.
 
 I tried to translate this into the new mechanism and thought it  
 should read like so:
 
 \startxmlsetups xml:mysetups
 \xmlsetsetup{\xmldocument}{text:p|section|quotation}{xml:*}
 \stopxmlsetups
 
 \xmlregistersetup{xml:mysetups}
 
 \startxmlsetups xml:p
 \xmlflush{#1}\endgraf
 \stopxmlsetups
 
 \startxmlsetups xml:quotation
 \quotation{\xmlflush{#1}}
 \stopxmlsetups
 
 \startxmlsetups xml:section
 \section{\xmlatt{#1}{section}{title}}
 \stopxmlsetups

\startxmlsetups xml:section
\section{\xmlatt{#1}{section}{title}}
\xmlflush{#1}
\stopxmlsetups

 \starttext
 \xmlprocess{main}{test.xml}{}
 \stoptext
 
 But then, I only get invalid xml file in the output.

Remove the DOCDATA definition from your xml file, seems the parser has
problems with  pairs inside of the DOCDATA definition.

The following line give me a pdf file

!DOCTYPE document [
!ELEMENT section (p)
]

but the next one

!DOCTYPE document [
!ELEMENT section (p)
]

give only invalid xml file.

Wolfgang
___
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml in mkiv

2008-03-16 Thread Wolfgang Schuster
  This seems like a bug to me. This did only happen with the content in
  the first line because I inserted a empty first line at the begin of
  the line the xml header disappeared from the pdf, could be related to
  a wrong catcode for the  at the beginning of the line.
 
 
 OK, then this is a bug. The declaration has to be on the first line,  
 my editor (emacs in nxml mode) doesn't even let me save the file when  
 I introduce a first blank line before it.

No problems with Scite or EmEditor.

  \xmlprocess{main}{filename.xml}{} works for me.
 
 Yes, but that would mean you need an environment for every xml file  
 you want to process. I have now tried
 \xmlprocess{main}{\inputfilename}{}
 
 and this seems to work.
 
  \startxmlsetups xml:section
  \section{\xmlatt{#1}{section}{title}}
  \stopxmlsetups
 
  \startxmlsetups xml:section
  \section{\xmlatt{#1}{section}{title}}
  \xmlflush{#1}
  \stopxmlsetups
 
 Thanks! I experimented a bit more; I think it has to be
 
 \startxmlsetups xml:section
 \section{\xmlatt{#1}{title}}
 \xmlflush{#1}
 \stopxmlsetups
 
 (at least, this seems to work for me...)

I did the same thing in my example but forgot it in my last mail.

  \starttext
  \xmlprocess{main}{test.xml}{}
  \stoptext
 
  But then, I only get invalid xml file in the output.
 
  Remove the DOCDATA definition from your xml file, seems the parser has
  problems with  pairs inside of the DOCDATA definition.
 
  The following line give me a pdf file
 
  !DOCTYPE document [
  !ELEMENT section (p)
  ]
 
 Hmm, but this isn't valid xml?

I know but it could help to find the wrong definition in the xml parser.

  but the next one
 
  !DOCTYPE document [
  !ELEMENT section (p)
  ]
 
 Whereas this is valid and processed without problems by mkii?

You should know, MkII read the xml code with TeX macros whereas MkIV
use lpeg to read the xml code.

 Hmm, either mkiv xml handling is still a bit immature, or I'm not  
 mature enough to use it yet :-)

The MkIV is new and still under development, tests like your one help
to find errors and to fix them.

Wolfgang
___
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___


Re: [NTG-context] processing xml in mkiv

2008-03-16 Thread Hans Hagen
Thomas A. Schmitz wrote:
 On Mar 16, 2008, at 1:51 PM, Wolfgang Schuster wrote:
 
 This seems like a bug to me. This did only happen with the content in
 the first line because I inserted a empty first line at the begin of
 the line the xml header disappeared from the pdf, could be related to
 a wrong catcode for the  at the beginning of the line.

 
 OK, then this is a bug. The declaration has to be on the first line,  
 my editor (emacs in nxml mode) doesn't even let me save the file when  
 I introduce a first blank line before it.

indeed ther eis something weird, but it may as well be something in 
lautex itself, so taco has to look into it too

what happens is:

\def\processXMLfilegrouped#1{{\enableXML\processfile{#1}\relax\ifmmode\else\par\fi}}

it looks like the new catcode regime lags one line behind here

-
   Hans Hagen | PRAGMA ADE
   Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
  tel: 038 477 53 69 | fax: 038 477 53 74 | www.pragma-ade.com
  | www.pragma-pod.nl
-
___
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://tex.aanhet.net
archive  : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___