Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Adding to the correct answers for XPath 1.0, in XPath 2.0 there is the <a href="http://www.w3.org/TR/xmlschema-2/#integer" rel="nofollow noreferrer"><strong>xs:integer</strong></a> datatype and <strong>there is no maximum for the absolute value of an xs:integer</strong>.</p> <p><a href="http://www.saxonica.com" rel="nofollow noreferrer"><strong>Saxon</strong></a> implements BigInteger arithmetic, and given your code (slightly changed with the addition of the xs:integer type):</p> <p> </p> <pre><code>&lt;xsl:template match="factorial" name="factorial"&gt; &lt;xsl:param name="n" as="xs:integer" select="xs:integer(@n)" /&gt; &lt;xsl:param name="f" as="xs:integer" select="1" /&gt; &lt;xsl:if test="$n gt 1"&gt; &lt;xsl:call-template name="factorial"&gt; &lt;xsl:with-param name="n"&gt; &lt;xsl:value-of select="$n - 1" /&gt; &lt;/xsl:with-param&gt; &lt;xsl:with-param name="f"&gt; &lt;xsl:value-of select="$f * $n" /&gt; &lt;/xsl:with-param&gt; &lt;/xsl:call-template&gt; &lt;/xsl:if&gt; &lt;xsl:if test="$n = 1"&gt; &lt;xsl:value-of select="$f" /&gt; &lt;/xsl:if&gt; &lt;/xsl:template&gt; </code></pre> <p></p> <p>when it is applied to the following XML document:</p> <pre><code>&lt;factorial n = "171"/&gt; </code></pre> <p>the correct result is produced:</p> <p>1241018070217667823424840524103103992616605577501693185388951803611996075221691752992751978120487585576464959501670387052809889858690710767331242032218484364310473577889968548278290754541561964852153468318044293239598173696899657235903947616152278558180061176365108428800000000000000000000000000000000000000000</p> <p>Certainly, I'd prefer to write this using the <a href="http://fxsl.sf.net" rel="nofollow noreferrer"><strong>FXSL library</strong></a> in a single expression:</p> <p><strong>&nbsp;&nbsp;&nbsp;&nbsp;<code>f:foldl(f:mult(), 1, 1 to 171)</code></strong></p> <p>within this XSLT stylesheet:</p> <pre><code>&lt;xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:f="http://fxsl.sf.net/" &gt; &lt;xsl:import href="../f/func-dvc-foldl.xsl"/&gt; &lt;xsl:import href="../f/func-Operators.xsl"/&gt; &lt;xsl:output encoding="UTF-8" method="text"/&gt; &lt;xsl:template match="/"&gt; &lt;xsl:value-of select="f:foldl(f:mult(), 1, 1 to 171)"/&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre>
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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