[NTG-context] processing xml with lua

Thomas A. Schmitz thomas.schmitz at uni-bonn.de
Tue Mar 5 09:47:48 CET 2013


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


   <b><c>Fruit</c> <d><e>Apple</e></d></b>
   <b><c>Vegetable</c> <d><q>Carot</q></d></b>

\startxmlsetups xml:testsetups


\startxmlsetups xml:a

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

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

\startxmlsetups xml:q

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
     context("This Type is already known: ") context(lookuptable[mytype])



More information about the ntg-context mailing list