title: How to XPath sum() all previous nodes in a XSL for-each loop?
body: <p>The source XML (this is just foobar data, in reality it is thousands of rows wich can be both positive and negative):</p>
  
  <pre><code>&lt;accounting&gt;
      &lt;entry id="1"&gt;
          &lt;accounting_date&gt;2010-10-29&lt;/accounting_date&gt;
          &lt;transfer_date&gt;2010-10-29&lt;/transfer_date&gt;
          &lt;description&gt;Start balance&lt;/description&gt;
          &lt;vat&gt;0&lt;/vat&gt;
          &lt;sum&gt;87287&lt;/sum&gt;
      &lt;/entry&gt;
      &lt;entry id="2"&gt;
          &lt;accounting_date&gt;2011-01-24&lt;/accounting_date&gt;
          &lt;transfer_date&gt;2011-02-17&lt;/transfer_date&gt;
          &lt;description&gt;Bill 1&lt;/description&gt;
          &lt;vat&gt;175&lt;/vat&gt;
          &lt;sum&gt;875&lt;/sum&gt;
      &lt;/entry&gt;
      &lt;entry id="3"&gt;
          &lt;accounting_date&gt;2011-01-31&lt;/accounting_date&gt;
          &lt;transfer_date&gt;2011-01-18&lt;/transfer_date&gt;
          &lt;description&gt;Bill 2&lt;/description&gt;
          &lt;vat&gt;350&lt;/vat&gt;
          &lt;sum&gt;1750&lt;/sum&gt;
      &lt;/entry&gt;
  &lt;/accounting&gt;
  </code></pre>
  
  <p>I want to transform this XML to an HTML table to display to the user. Most of the transformation is just putting values in the right places, but the balance-field is giving me headache.</p>
  
  <p>My XSLT (that does not work):</p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Accounting date&lt;/th&gt;
          &lt;th&gt;Description&lt;/th&gt;
          &lt;th&gt;Sum&lt;/th&gt;
          &lt;th&gt;Balanche&lt;/th&gt;
      &lt;/tr&gt;
      &lt;xsl:for-each select="/accounting/entry"&gt;
          &lt;tr&gt;
              &lt;td&gt;&lt;xsl:value-of select="accounting_date" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;xsl:value-of select="description" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;xsl:value-of select="sum" /&gt;&lt;/td&gt;
              &lt;td&gt;&lt;xsl:value-of select="sum(../entry[position() &amp;lt; current()/position()]/sum)" /&gt;&lt;/td&gt;&lt;!-- This XPath is the problem! --&gt;
          &lt;/tr&gt;
      &lt;/xsl:for-each&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Expected result:</p>
  
  <pre><code>&lt;table&gt;
      &lt;tr&gt;
          &lt;th&gt;Accounting date&lt;/th&gt;
          &lt;th&gt;Description&lt;/th&gt;
          &lt;th&gt;Sum&lt;/th&gt;
          &lt;th&gt;Balanche&lt;/th&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;2010-10-29&lt;/td&gt;
          &lt;td&gt;Start balance&lt;/td&gt;
          &lt;td&gt;87287&lt;/td&gt;
          &lt;td&gt;87287&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;2011-01-24&lt;/td&gt;
          &lt;td&gt;Bill 1&lt;/td&gt;
          &lt;td&gt;875&lt;/td&gt;
          &lt;td&gt;88162&lt;/td&gt;
      &lt;/tr&gt;
      &lt;tr&gt;
          &lt;td&gt;2011-01-31&lt;/td&gt;
          &lt;td&gt;Bill 2&lt;/td&gt;
          &lt;td&gt;1750&lt;/td&gt;
          &lt;td&gt;89912&lt;/td&gt;
      &lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Chrome is blank, and Firefox gives me:</p>
  
  <pre><code>Error loading stylesheet: XPath parse failure: Name or Nodetype test expected:
  </code></pre>
  
  <p>I'm stuck, please help. :)</p>