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> <b><c>Fruit</c> <d><e>Apple</e></d></b> <b><c>Vegetable</c> <d><q>Carot</q></d></b> <b><c>Fruit</c></b> <b><c>Vegetable</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 -----------------------------------------------------------------