* luatex and xml
@ 2008-05-18 0:20 WN
2008-05-18 8:21 ` Wolfgang Schuster
2008-05-18 14:23 ` Hans Hagen
0 siblings, 2 replies; 4+ messages in thread
From: WN @ 2008-05-18 0:20 UTC (permalink / raw)
To: mailing list for ConTeXt users
Hi,
I am trying to parse a xml file with mkiv to process a list of invoices
(factuur in dutch).
The xml file looks like this
<?xml version='1.0 standalone='yes' ?>
<factuur>
<nummer>123456789</nummer>
<datum>1 januari 2008</datum>
<medewerker></medewerker>
<regels>
<omschrijving>Omschrijving geleverde dienst a</omschrijving>
<bedrag>1500,00</bedrag>
<omschrijving>Omschrijving geleverde dienst b</omschrijving>
<bedrag>200,00</bedrag>
</regels>
</factuur>
I want to extract and sum the invoices (regels). I managed to get things
working (printing)
but don't know how to assign these values into lua variables for the
summing.
The test code looks like this
% engine=luatex
\starttext
\startluacode
document.xml = document.xml or { } -- define namespace
document.xml = xml.load("factuur.xml") -- load the file
n = xml.count(document.xml, "/factuur/regels/omschrijving")
for i = 1, n do
--
-- here I want to assign the values returned by xml.filter into local
variable amount
--
xml.sprint(xml.filter(document.xml, "/factuur/regels/bedrag/position("
.. i .. ")" ))
end
\stopluacode
\stoptext
Kind regards
WN
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: luatex and xml
2008-05-18 0:20 luatex and xml WN
@ 2008-05-18 8:21 ` Wolfgang Schuster
2008-05-18 13:23 ` WN
2008-05-18 14:23 ` Hans Hagen
1 sibling, 1 reply; 4+ messages in thread
From: Wolfgang Schuster @ 2008-05-18 8:21 UTC (permalink / raw)
To: ntg-context
[-- Attachment #1: Type: text/plain, Size: 1856 bytes --]
Hi,
take a look into invoice.tex in my attachment.
Wolfgang
On Sun, 18 May 2008 02:20:00 +0200
WN <wneimeijer@tiscali.nl> wrote:
> Hi,
>
> I am trying to parse a xml file with mkiv to process a list of invoices
> (factuur in dutch).
>
> The xml file looks like this
>
> <?xml version='1.0 standalone='yes' ?>
> <factuur>
> <nummer>123456789</nummer>
> <datum>1 januari 2008</datum>
> <medewerker></medewerker>
> <regels>
> <omschrijving>Omschrijving geleverde dienst a</omschrijving>
> <bedrag>1500,00</bedrag>
> <omschrijving>Omschrijving geleverde dienst b</omschrijving>
> <bedrag>200,00</bedrag>
> </regels>
> </factuur>
>
> I want to extract and sum the invoices (regels). I managed to get things
> working (printing)
> but don't know how to assign these values into lua variables for the
> summing.
> The test code looks like this
>
> % engine=luatex
> \starttext
>
> \startluacode
> document.xml = document.xml or { } -- define namespace
> document.xml = xml.load("factuur.xml") -- load the file
> n = xml.count(document.xml, "/factuur/regels/omschrijving")
>
> for i = 1, n do
> --
> -- here I want to assign the values returned by xml.filter into local
> variable amount
> --
>
> xml.sprint(xml.filter(document.xml, "/factuur/regels/bedrag/position("
> .. i .. ")" ))
>
> end
> \stopluacode
> \stoptext
>
> Kind regards
> WN
> ___________________________________________________________________________________
> 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
> ___________________________________________________________________________________
[-- Attachment #2: invoice.zip --]
[-- Type: application/zip, Size: 2404 bytes --]
[-- Attachment #3: Type: text/plain, Size: 487 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://tex.aanhet.net
archive : https://foundry.supelec.fr/projects/contextrev/
wiki : http://contextgarden.net
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: luatex and xml
2008-05-18 8:21 ` Wolfgang Schuster
@ 2008-05-18 13:23 ` WN
0 siblings, 0 replies; 4+ messages in thread
From: WN @ 2008-05-18 13:23 UTC (permalink / raw)
To: schuster.wolfgang; +Cc: mailing list for ConTeXt users
Thanks Wolfgang for your time and the attachments you send me.
I don't want to sound ungrateful for the hard work and
for the nice module you send me, but I was looking for another solution
where I don't have to use Context macro's and setups.
I want to use a little bit of lua code to get to the data I want. I think
I will have greater control independent of the xml macro's (to be honest
I find
them difficult to understand).
The solution I am looking for, is to use the function xml.filter
(defined in l-xml.lua)
and to assign the outcome to local variables.
Kind regards
Wim
> Hi,
>
> take a look into invoice.tex in my attachment.
>
> Wolfgang
>
> On Sun, 18 May 2008 02:20:00 +0200
> WN <wneimeijer@tiscali.nl> wrote:
>
>> Hi,
>>
>> I am trying to parse a xml file with mkiv to process a list of invoices
>> (factuur in dutch).
>>
>> The xml file looks like this
>>
>> <?xml version='1.0 standalone='yes' ?>
>> <factuur>
>> <nummer>123456789</nummer>
>> <datum>1 januari 2008</datum>
>> <medewerker></medewerker>
>> <regels>
>> <omschrijving>Omschrijving geleverde dienst a</omschrijving>
>> <bedrag>1500,00</bedrag>
>> <omschrijving>Omschrijving geleverde dienst b</omschrijving>
>> <bedrag>200,00</bedrag>
>> </regels>
>> </factuur>
>>
>> I want to extract and sum the invoices (regels). I managed to get things
>> working (printing)
>> but don't know how to assign these values into lua variables for the
>> summing.
>> The test code looks like this
>>
>> % engine=luatex
>> \starttext
>>
>> \startluacode
>> document.xml = document.xml or { } -- define namespace
>> document.xml = xml.load("factuur.xml") -- load the file
>> n = xml.count(document.xml, "/factuur/regels/omschrijving")
>>
>> for i = 1, n do
>> --
>> -- here I want to assign the values returned by xml.filter into local
>> variable amount
>> --
>>
>> xml.sprint(xml.filter(document.xml, "/factuur/regels/bedrag/position("
>> .. i .. ")" ))
>>
>> end
>> \stopluacode
>> \stoptext
>>
>> Kind regards
>> WN
>> ___________________________________________________________________________________
>> 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
>> ___________________________________________________________________________________
>>
>> ------------------------------------------------------------------------
>>
>> ___________________________________________________________________________________
>> 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
>> ___________________________________________________________________________________
___________________________________________________________________________________
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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: luatex and xml
2008-05-18 0:20 luatex and xml WN
2008-05-18 8:21 ` Wolfgang Schuster
@ 2008-05-18 14:23 ` Hans Hagen
1 sibling, 0 replies; 4+ messages in thread
From: Hans Hagen @ 2008-05-18 14:23 UTC (permalink / raw)
To: mailing list for ConTeXt users
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 : 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
___________________________________________________________________________________
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2008-05-18 14:23 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-05-18 0:20 luatex and xml WN
2008-05-18 8:21 ` Wolfgang Schuster
2008-05-18 13:23 ` WN
2008-05-18 14:23 ` Hans Hagen
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).