From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.io/gmane.comp.tex.context/103924 Path: news.gmane.org!.POSTED.blaine.gmane.org!not-for-mail From: Geert Verhaag Newsgroups: gmane.comp.tex.context Subject: Request for xml.filter explanation! Date: Wed, 10 Apr 2019 21:27:10 +0200 Message-ID: <52377958-b72e-12aa-8f52-b3280670b842@ziggo.nl> Reply-To: mailing list for ConTeXt users Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="===============5296698065683683110==" Injection-Info: blaine.gmane.org; posting-host="blaine.gmane.org:195.159.176.226"; logging-data="46509"; mail-complaints-to="usenet@blaine.gmane.org" User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 To: ntg-context@ntg.nl Original-X-From: ntg-context-bounces@ntg.nl Wed Apr 10 21:27:24 2019 Return-path: Envelope-to: gctc-ntg-context-518@m.gmane.org Original-Received: from zapf.boekplan.nl ([5.39.185.232] helo=zapf.ntg.nl) by blaine.gmane.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1hEIsV-000By0-HE for gctc-ntg-context-518@m.gmane.org; Wed, 10 Apr 2019 21:27:23 +0200 Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 474F4119C79; Wed, 10 Apr 2019 21:27:14 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PBXXidSykbg8; Wed, 10 Apr 2019 21:27:13 +0200 (CEST) Original-Received: from zapf.ntg.nl (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 5C63E119C7B; Wed, 10 Apr 2019 21:27:13 +0200 (CEST) Original-Received: from localhost (localhost [127.0.0.1]) by zapf.ntg.nl (Postfix) with ESMTP id 2944B119C79 for ; Wed, 10 Apr 2019 21:27:12 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at zapf.boekplan.nl Original-Received: from zapf.ntg.nl ([127.0.0.1]) by localhost (zapf.ntg.nl [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id IdT-CZLeS5mz for ; Wed, 10 Apr 2019 21:27:11 +0200 (CEST) Original-Received: from smtpq4.mnd.mail.iss.as9143.net (smtpq4.mnd.mail.iss.as9143.net [212.54.34.167]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by zapf.ntg.nl (Postfix) with ESMTPS id 833EC119C76 for ; Wed, 10 Apr 2019 21:27:11 +0200 (CEST) Original-Received: from [212.54.34.114] (helo=smtp6.mnd.mail.iss.as9143.net) by smtpq4.mnd.mail.iss.as9143.net with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1hEIrl-0007iA-9X for ntg-context@ntg.nl; Wed, 10 Apr 2019 21:26:37 +0200 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=simple/simple; d=ziggo.nl; s=201809corplgsmtpnl; h=MIME-Version:Date:Message-ID:Subject:From:To; bh=AYaXuKnt+KL3osf9nKqHQ0UhOIn1O2FV6CG5kr+MjaM=; b=W07IBfWsC6Er6WY2aXCgB4JG6J /PT3eF30lzYNF3vMsCrQef7a9ewUyKiWaR1slq4RspeDufacsD1EW4fux2vz1RZncMBu8ny4g2odI tsPy1o9jWEVHLPLj0htIsXZbZDeCCRF4xSm5ZQEhVZZME9bQyMmz0GrcT4x+lpu3/tfAd4Wja/KYt N5HIQ31+lmd53G0o+3jPECH5o1Fs6iTXRj7iOcJ5A8lW/cy6xK2IVVqMhQ1kg6bvwjYSj4Na4C4F6 CnsGDomaZfDU0XwkewN+VTFpSI7G2e6GYQS56O9U8QsRITiijbTjWt4UoPIx9PFkWgiVUfTKXKlAF Sf2Qqw2A==; Original-Received: from 217-102-215-195.cable.dynamic.v4.ziggo.nl ([217.102.215.195]) by smtp6.mnd.mail.iss.as9143.net with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1hEIrl-0005FQ-5G for ntg-context@ntg.nl; Wed, 10 Apr 2019 21:26:37 +0200 Content-Language: en-US X-SourceIP: 217.102.215.195 X-Authenticated-Sender: verhaaggchm@ziggo.nl (via SMTP) X-Ziggo-spambar: / X-Ziggo-spamscore: 0.0 X-Ziggo-spamreport: CMAE Analysis: v=2.3 cv=ab0fYigt c=1 sm=1 tr=0 a=fup8kj6D1GK+0Yss58Du6A==:17 a=9+rZDBEiDlHhcck0kWbJtElFXBc=:19 a=oexKYjalfGEA:10 a=r77TgQKjGQsHNAKrUKIA:9 a=lhKKJhl00FP9rSm5rIwA:9 a=J16LKIFlgxW3IyPF:21 a=f9pWAYg6sJXVAath:21 a=QEXdDO2ut3YA:10 a=zTl6lpG1egpY7o9gtL8A:9 a=MLO6ewt2kpBU_Lsw:21 a=_W_S_7VecoQA:10 X-Ziggo-Spam-Status: No X-BeenThere: ntg-context@ntg.nl X-Mailman-Version: 2.1.26 Precedence: list List-Id: mailing list for ConTeXt users List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ntg-context-bounces@ntg.nl Original-Sender: "ntg-context" Xref: news.gmane.org gmane.comp.tex.context:103924 Archived-At: This is a multi-part message in MIME format. --===============5296698065683683110== Content-Type: multipart/alternative; boundary="------------FBADE1C7BBBC06411690B638" Content-Language: en-US This is a multi-part message in MIME format. --------------FBADE1C7BBBC06411690B638 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Hi, I've the following xml file: *     a paragraph of text   40.2       another paragraph of text   10.7       still another paragraph!   20.5   * 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 -- --------------FBADE1C7BBBC06411690B638 Content-Type: text/html; charset=utf-8 Content-Transfer-Encoding: 8bit

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
--


--------------FBADE1C7BBBC06411690B638-- --===============5296698065683683110== Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: base64 Content-Disposition: inline X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX18KSWYgeW91ciBxdWVzdGlvbiBpcyBvZiBpbnRlcmVz dCB0byBvdGhlcnMgYXMgd2VsbCwgcGxlYXNlIGFkZCBhbiBlbnRyeSB0byB0aGUgV2lraSEKCm1h aWxsaXN0IDogbnRnLWNvbnRleHRAbnRnLm5sIC8gaHR0cDovL3d3dy5udGcubmwvbWFpbG1hbi9s aXN0aW5mby9udGctY29udGV4dAp3ZWJwYWdlICA6IGh0dHA6Ly93d3cucHJhZ21hLWFkZS5ubCAv IGh0dHA6Ly9jb250ZXh0LmFhbmhldC5uZXQKYXJjaGl2ZSAgOiBodHRwczovL2JpdGJ1Y2tldC5v cmcvcGhnL2NvbnRleHQtbWlycm9yL2NvbW1pdHMvCndpa2kgICAgIDogaHR0cDovL2NvbnRleHRn YXJkZW4ubmV0Cl9fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19f X19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fX19fCg== --===============5296698065683683110==--