Recursion in XPath 3.1 inline function definition

Hi XSLT community group,
   I 've following XSLT3 stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                         version="3.0">

  <xsl:output method="xml" indent="yes"/>

  <xsl:variable name="factorial" select="function($num) { if ($num eq
0) then 1 else ($num * $factorial($num - 1)) }"/>

  <xsl:template match="/">
      <result>
          <answer>
              <xsl:value-of select="$factorial(2)"/>
         </answer>
         <answer>
             <xsl:value-of select="$factorial(3)"/>
         </answer>
        <answer>
            <xsl:value-of select="$factorial(4)"/>
        </answer>
    </result>
  </xsl:template>

</xsl:stylesheet>

Within this stylesheet, value of the variable "factorial" is an XPath
3.1 inline function definition that uses recursion. I think, that this
stylsheet when run should produce an XSL transformation result as
follows:

<?xml version="1.0" encoding="UTF-8"?><result>
   <answer>2</answer>
   <answer>6</answer>
   <answer>24</answer>
</result>

Saxon-HE 12.4 has issues running this stylesheet, and produces
following XSL transformation result:

Variable $factorial cannot be used within its own declaration

Please take appropriate measures to solve an XSL transformation issue
mentioned within this mail. I'm not sure, but probably an XSLT3 test
case corresponding to this use case should be added to XSLT3 test
suite.


-- 
Regards,
Mukul Gandhi

Received on Saturday, 29 March 2025 08:29:08 UTC