<html>
  <head>

    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  </head>
  <body text="#000000" bgcolor="#FFFFFF">
    <p>Hi,</p>
    <p>I've the following xml file:</p>
    <p><b><font size="-1"><?xml version='1.0' standalone='yes?><br>
          <br>
          <content><br>
           <object mid="a"><br>
            <text>a paragraph of text</text><br>
            <value>40.2</value><br>
           </object><br>
           <object mid="b"><br>
            <text>another paragraph of text</text><br>
            <value>10.7</value><br>
           </object><br>
           <object mid="c"><br>
            <text>still another paragraph!</text><br>
            <value>20.5</value><br>
           </object><br>
          </content></font></b></p>
    <p>And want to calculate the total value of all the objects:</p>
    <p>like so:</p>
    <p><b><font size="-1">\startxmlsetups xml:example:base<br>
            \xmlsetsetup{#1}{content|object}{xml:example:*}<br>
          \stopxmlsetups<br>
          <br>
          \xmlregisterdocumentsetup{example}{xml:example:base}<br>
          <br>
          \startxmlsetups xml:example:content<br>
          totalvalue: \xmlfunction{#1}{totalvalue}<br>
          \xmlflush{#1} \endgraf<br>
          \stopxmlsetups<br>
          <br>
          \startxmlsetups xml:example:object<br>
          attribute : \xmlatt{#1}{mid} \par<br>
          \stopxmlsetups<br>
          <br>
          % LUA<br>
          <br>
          \startluacode<br>
          function xml.functions.totalvalue(root)<br>
          local score = 0<br>
          for e in xml.collected(root,"/object") do<br>
          tex.write('Okay!')<br>
          --score = score + xml.filter(e,"xml:///value/number()") or 0<br>
          end<br>
          tex.write(score)<br>
          end<br>
          \stopluacode<br>
          <br>
          \starttext<br>
          <br>
          \xmlprocessfile{example}{content.xml}{}<br>
          <br>
          \stoptext</font></b></p>
    <p><b><font size="-1"><br>
        </font></b></p>
    <p>When I run this example I get:</p>
    <p><b><font size="-1">totalvalue: Okay!Okay!Okay!0 attribute : a<br>
          attribute : b<br>
          attribute : c</font></b></p>
    <p>That looks allright!</p>
    <p>But when I incorporate the line:</p>
    <p><b><font size="-1">score = score +
          xml.filter(e,"xml:///value/number()") or 0</font></b></p>
    <p>the following Lua error is thrown:<br>
      <b><font size="-1"></font></b></p>
    <p><b><font size="-1">! LuaTeX error [string "\directlua "]:5:
          attempt to perform arithmetic on a nil value</font></b></p>
    <p>Has anybody any idea what I'm doing wrong here? The manual <b>xml-mkiv.pdf</b>
      doesn't give any clue about this!</p>
    Regards,<br>
    Gerard<br>
    <div class="moz-signature">-- <br>
      <meta http-equiv="content-type" content="text/html; charset=UTF-8">
      <title></title>
      <br>
      <div class="moz-signature"><br>
      </div>
    </div>
  </body>
</html>