Created
December 12, 2018 08:58
-
-
Save welblaud/b3689adc9cd347b1d5322a91260edfbe to your computer and use it in GitHub Desktop.
XSLT recursive template call – calculating factorial
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Factorial calculated with XSLT recursion. --> | |
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
version="1.0"> | |
<xsl:output method="text"/> | |
<xsl:param name="number" select="9"/> | |
<xsl:template match="/"> | |
<xsl:call-template name="factorial"> | |
<xsl:with-param name="n" select="$number"/> | |
</xsl:call-template> | |
</xsl:template> | |
<xsl:template name="factorial"> | |
<xsl:param name="n"/> | |
<xsl:variable name="m"> | |
<xsl:if test="$n <= 1"> | |
<xsl:text>1</xsl:text> | |
</xsl:if> | |
<xsl:if test="$n > 1"> | |
<xsl:call-template name="factorial"> | |
<xsl:with-param name="n" select="$n - 1"/> | |
</xsl:call-template> | |
</xsl:if> | |
</xsl:variable> | |
<xsl:value-of select="$m * $n"/> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment