From: Geert Verhaag <verhaaggchm@ziggo.nl>
To: ntg-context@ntg.nl
Subject: Request for xml.filter explanation!
Date: Wed, 10 Apr 2019 21:27:10 +0200 [thread overview]
Message-ID: <52377958-b72e-12aa-8f52-b3280670b842@ziggo.nl> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 1610 bytes --]
Hi,
I've the following xml file:
*<?xml version='1.0' standalone='yes?>
<content>
<object mid="a">
<text>a paragraph of text</text>
<value>40.2</value>
</object>
<object mid="b">
<text>another paragraph of text</text>
<value>10.7</value>
</object>
<object mid="c">
<text>still another paragraph!</text>
<value>20.5</value>
</object>
</content>*
And want to calculate the total value of all the objects:
like so:
*\startxmlsetups xml:example:base
\xmlsetsetup{#1}{content|object}{xml:example:*}
\stopxmlsetups
\xmlregisterdocumentsetup{example}{xml:example:base}
\startxmlsetups xml:example:content
totalvalue: \xmlfunction{#1}{totalvalue}
\xmlflush{#1} \endgraf
\stopxmlsetups
\startxmlsetups xml:example:object
attribute : \xmlatt{#1}{mid} \par
\stopxmlsetups
% LUA
\startluacode
function xml.functions.totalvalue(root)
local score = 0
for e in xml.collected(root,"/object") do
tex.write('Okay!')
--score = score + xml.filter(e,"xml:///value/number()") or 0
end
tex.write(score)
end
\stopluacode
\starttext
\xmlprocessfile{example}{content.xml}{}
\stoptext*
*
*
When I run this example I get:
*totalvalue: Okay!Okay!Okay!0 attribute : a
attribute : b
attribute : c*
That looks allright!
But when I incorporate the line:
*score = score + xml.filter(e,"xml:///value/number()") or 0*
the following Lua error is thrown:
**
*! LuaTeX error [string "\directlua "]:5: attempt to perform arithmetic
on a nil value*
Has anybody any idea what I'm doing wrong here? The manual
*xml-mkiv.pdf* doesn't give any clue about this!
Regards,
Gerard
--
[-- Attachment #1.2: Type: text/html, Size: 3183 bytes --]
[-- Attachment #2: Type: text/plain, Size: 493 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://context.aanhet.net
archive : https://bitbucket.org/phg/context-mirror/commits/
wiki : http://contextgarden.net
___________________________________________________________________________________
next reply other threads:[~2019-04-10 19:27 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-10 19:27 Geert Verhaag [this message]
2019-04-11 15:33 ` Hans Hagen
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=52377958-b72e-12aa-8f52-b3280670b842@ziggo.nl \
--to=verhaaggchm@ziggo.nl \
--cc=ntg-context@ntg.nl \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).