xsl-list
[Top] [All Lists]

Re: [xsl] Factorial Calculation

2006-04-06 00:01:07
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(_dot_)bishnoi(_at_)adeptia(_dot_)com> wrote:
Hi
   Can we calculate Factorial of number in XSLT using iteration or
Call-Templates???


Thanks
Pankaj

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>