Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Knowing nothing else about your input data (I have no idea why you chose <em>not to use actual XML</em>), I'm going to have to to guess a little:</p> <pre><code>&lt;Budget&gt; &lt;Table1&gt; &lt;AllocID&gt;1000&lt;/AllocID&gt; &lt;AllocID&gt;2000&lt;/AllocID&gt; &lt;AllocID&gt;3000&lt;/AllocID&gt; &lt;/Table1&gt; &lt;Table2&gt; &lt;AllocID&gt;1000&lt;/AllocID&gt; &lt;AllocID&gt;2000&lt;/AllocID&gt; &lt;/Table2&gt; &lt;/Budget&gt; </code></pre> <p>Easiest is the <a href="http://www.w3.org/TR/xpath#function-sum" rel="nofollow noreferrer">XPath <code>sum()</code> function</a> along with the right XPath expression:</p> <pre><code>&lt;!-- this will return 3000 for the above input --&gt; &lt;xsl:template match="/" &gt; &lt;xsl:value-of select=" sum(Budget/Table1/AllocID[. = //Budget/Table2/AllocID]) " /&gt; &lt;/xsl:template&gt; </code></pre> <p>Running sums can also be calculated with a recursive function, like this:</p> <pre><code>&lt;!-- this will also return 3000 for the above input --&gt; &lt;xsl:template match="/" &gt; &lt;xsl:call-template name="total"&gt; &lt;xsl:with-param name="nodes" select=" Budget/Table1/AllocID[. = //Budget/Table2/AllocID] " /&gt; &lt;/xsl:call-template&gt; &lt;/xsl:template&gt; &lt;xsl:template name="total"&gt; &lt;xsl:param name="nodes" /&gt; &lt;xsl:choose&gt; &lt;!-- either there is something to calculate... --&gt; &lt;xsl:when test="string(number($nodes[1])) != 'NaN'"&gt; &lt;xsl:variable name="subtotal"&gt; &lt;xsl:call-template name="total"&gt; &lt;xsl:with-param name="nodes" select="$nodes[position() &amp;gt; 1]" /&gt; &lt;/xsl:call-template&gt; &lt;/xsl:variable&gt; &lt;xsl:value-of select="number($nodes[1]) + $subtotal" /&gt; &lt;/xsl:when&gt; &lt;!-- ...or we assume 0 --&gt; &lt;xsl:otherwise&gt; &lt;xsl:value-of select="0" /&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; </code></pre> <p>This is slower, but allows for greater flexibility in the calculation process. You can replace all the non-numeric values with 0, for example. Or use different values of the given nodes according to your own rules.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload