Re: [xsl] Factorial Calculation

Subject: Re: [xsl] Factorial Calculation
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Thu, 6 Apr 2006 12:30:53 +0530
Hi Pankaj,
  We can do so as shown below..

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="1.0">

<xsl:output method="text" />

<xsl:variable name="number" select="5" />

<xsl:template match="/">
  <xsl:call-template name="factorial">
    <xsl:with-param name="number" select="$number" />
  </xsl:call-template>
</xsl:template>

<xsl:template name="factorial">
  <xsl:param name="number" />

  <xsl:choose>
    <xsl:when test="$number = 1">
      1
    </xsl:when>
    <xsl:otherwise>
      <xsl:variable name="x">
        <xsl:call-template name="factorial">
           <xsl:with-param name="number" select="$number - 1" />
        </xsl:call-template>
      </xsl:variable>
      <xsl:value-of select="$number * $x" />
    </xsl:otherwise>
  </xsl:choose>
</xsl:template>

</xsl:stylesheet>

Regards,
Mukul

On 4/6/06, Pankaj Bishnoi <pankaj.bishnoi@xxxxxxxxxxx> wrote:
> Hi
>    Can we calculate Factorial of number in XSLT using iteration or
> Call-Templates???
>
>
> Thanks
> Pankaj

Current Thread