Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Remove the dot and you will always see 3000 because all @costs (independent from starting point) will be summed.</p> <pre class="lang-xml prettyprint-override"><code>&lt;xsl:value-of select="number(sum(//@cost))"/&gt; &lt;!-- + number($sum) --&gt; </code></pre> <p>Output will look like this: <code>30003000</code> </p> <p>But I assume that something is wrong with your approach. When you call a template recursive then the output will also will be printed as much as the template calls itself in your case. You need to print out the result at the end of your recursion</p> <p>Given this input:</p> <pre><code>&lt;root&gt; &lt;mileage value="15000"&gt; &lt;operation title="Replacing the engine oil" cost="500" /&gt; &lt;sparepart title="Oil filter" cost="250" /&gt; &lt;sparepart title="Motor oil" cost="1050" /&gt; &lt;/mileage&gt; &lt;mileage value="30000"&gt; &lt;repeating mileage="15000" /&gt; &lt;operation title="Replacement of spark" cost="1200" /&gt; &lt;/mileage&gt; &lt;/root&gt; </code></pre> <p>and using this xslt:</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:output omit-xml-declaration="yes" indent="yes"/&gt; &lt;xsl:strip-space elements="*"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:apply-templates select="root"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="root"&gt; &lt;xsl:apply-templates select="mileage[@value=30000]"/&gt; &lt;/xsl:template&gt; &lt;xsl:template match="mileage[@value]"&gt; &lt;xsl:param name="sum" select="number(0)" /&gt; &lt;xsl:variable name="milinkage"&gt;&lt;xsl:value-of select="number(repeating/@mileage)" /&gt;&lt;/xsl:variable&gt; &lt;xsl:variable name="newsum"&gt; &lt;xsl:value-of select="number(sum(.//@cost)) + $sum"/&gt; &lt;/xsl:variable&gt; &lt;xsl:apply-templates select="parent::*/mileage[@value=$milinkage]"&gt;&lt;xsl:with-param name="sum" select="number($newsum)" /&gt;&lt;/xsl:apply-templates&gt; &lt;xsl:if test="not(parent::*/mileage[@value=$milinkage])"&gt; &lt;xsl:value-of select="$newsum"/&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>gives the correct result: <code>3000</code></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. This table or related slice is empty.
    1. This table or related slice is empty.
    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