WN wrote:
> Hi,
>
> I am trying to parse a xml file with mkiv to process a list of invoices
> (factuur in dutch).
please wikify the following solution ...
% engine=luatex
\startbuffer[whatever]
<?xml version='1.0 standalone='yes' ?>
<factuur>
<nummer>123456789</nummer>
<datum>1 januari 2008</datum>
<medewerker>whoever</medewerker>
<regels>
<omschrijving>Omschrijving geleverde dienst
a</omschrijving><bedrag>1500,00</bedrag>
<omschrijving>Omschrijving geleverde dienst
b</omschrijving><bedrag>200,00</bedrag>
</regels>
</factuur>
\stopbuffer
\startxmlsetups xml:invoice
\xmlsetsetup{main}{factuur}{xml:*}
\stopxmlsetups
\xmlregistersetup{xml:invoice}
\startluacode
document.user = document.user or {}
function document.user.sum(root)
root = lxml.id(root)
local sum = 0
for r, d, k in xml.elements(root,"regels/bedrag") do
local data = xml.content(d[k])
data = data:gsub(",",".")
sum = sum + tonumber(data)
end
local result = string.format("%0.2f",sum)
result = result:gsub("%.",",")
tex.write(result)
end
\stopluacode
\startxmlsetups xml:factuur
... \ctxlua{document.user.sum("#1")} ...
\stopxmlsetups
\starttext
\xmlprocessbuffer{main}{whatever}{}
\stoptext
-----------------------------------------------------------------
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 : [email protected] / 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
___________________________________________________________________________________