Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>This transformation</strong>:</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:template match="/"&gt; &lt;xsl:call-template name="product"&gt; &lt;xsl:with-param name="pArgs" select="//zero"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:template&gt; &lt;xsl:template name="product"&gt; &lt;xsl:param name="pAccum" select="1"/&gt; &lt;xsl:param name="pArgs" select="/.."/&gt; &lt;xsl:choose&gt; &lt;xsl:when test="not($pArgs)"&gt; &lt;xsl:value-of select="$pAccum"/&gt; &lt;/xsl:when&gt; &lt;xsl:otherwise&gt; &lt;xsl:call-template name="product"&gt; &lt;xsl:with-param name="pAccum" select="$pAccum * count($pArgs[1]/ancestor::s)"/&gt; &lt;xsl:with-param name="pArgs" select="$pArgs[position() &gt; 1]"/&gt; &lt;/xsl:call-template&gt; &lt;/xsl:otherwise&gt; &lt;/xsl:choose&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p><strong>when applied on the provided XML document:</strong></p> <pre><code>&lt;nat&gt; &lt;s&gt; &lt;s&gt; &lt;zero/&gt; &lt;/s&gt; &lt;/s&gt; &lt;s&gt; &lt;s&gt; &lt;zero/&gt; &lt;/s&gt; &lt;/s&gt; &lt;s&gt; &lt;s&gt; &lt;zero/&gt; &lt;/s&gt; &lt;/s&gt; &lt;/nat&gt; </code></pre> <p><strong>produces the wanted, correct result:</strong></p> <pre><code>8 </code></pre> <p><strong>Explanation</strong>:</p> <p>Primitive recursion with stop condition -- empty argument node-set and an accumulator - parameter for passing the currently accumulated result to the next recursive call.</p>
    singulars
    1. This table or related slice is empty.
    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.
 

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