title: XQuery method, trying to sum values read from xml
body: <p>I'm pretty new to XQuery and I'm trying to write an example function that I can't get to work. 
  I want to read an xml file, parse out the "time" values, sum them as they're read and return the sum.
  This is trivial and I'm looking to build more functionality into it but I'd like to get this working first. 
  Also, I know there's a "sum" directive in XQuery that would do just this but I want to add more to it so the built-in sum is insufficient for my needs. </p>
  
  <p>Here's my function:</p>
  
  <pre>
  bool
  example(Zorba* aZorba)
  {
     XQuery_t lQuery = aZorba->compileQuery(
                          "for $i in fn:doc('/tmp/products.xml')//time"
                           "let $sum := xs:integer($i)"
                                   " return $sum"
  );
  
    DynamicContext* lCtx = lQuery->getDynamicContext();
  
    lCtx->setContextItemAsDocument("temp_measurements.xml", lDocStream);
  
    try {
      std::cout &lt;&lt; lQuery &lt;&lt; std::endl;
    } catch (DynamicException& e) {
      std::cerr &lt;&lt; e.getDescription() &lt;&lt; std::endl;
      return false;
    } catch (StaticException& f){
          std::cerr &lt;&lt; f.getDescription() &lt;&lt; f.getErrorCodeAsString(f.getErrorCode()) &lt;&lt; std::endl;
          return false;
    }
  }
  </pre>
  
  <p>It's called with an appropriate main(). If I comment out the line that starts "let $sum..." then this works in that it returns the time values as a series of integers like this:
  0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3....</p>
  
  <p>Input file looks like this:</p>
  
  <pre>
  &lt;?xml version="1.0" encoding="UTF-8"?>
  &lt;temps>
    &lt;temp>
      &lt;time>0&lt;/time>
      &lt;lat>0&lt;/lat>
      &lt;long>0&lt;/long>
      &lt;value>0&lt;/value>
    &lt;/temp>
    &lt;temp>
      &lt;time>1&lt;/time>
      &lt;lat>0&lt;/lat>
      &lt;long>1&lt;/long>
      &lt;value>0&lt;/value>
    &lt;/temp>
   ...
  </pre>