This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: power
- To: xsl-list at lists dot mulberrytech dot com
- Subject: Re: [xsl] power
- From: Goetz Bock <bock at blacknet dot de>
- Date: Tue, 22 May 2001 16:40:08 +0200
- References: <3B0A6E34.C416AD92@softsolutions.fr>
- Reply-To: xsl-list at lists dot mulberrytech dot com
On Tue, May 22 '01 at 16:48, SoftLiban ITANI Mohamed wrote:
> I need to do some calculations in my xsl, is there any power function??
> 2 power 3 = 8
No, but you can write a recursive template:
<xsl:template name="power">
<xsl:param name="value">1<xsl:param>
<xsl:param name="base">1<xsl:param>
<xsl:param name="power">0<xsl:param>
<xsl:choose>
<xsl:when test="$power=0">
<xsl:value-of select="$value"/>
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="power">
<xsl:with-param name="value">
<xsl:value-of select="$value * $base"/>
</xsl:with-param>
<xsl:with-param name="base">
<xsl:value-of select="$base"/>
</xsl:with-param>
<xsl:with-param name="power">
<xsl:value-of select="$power - 1"/>
</xsl:with-param>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
<xsl:template>
(NOTE: this was all done with out any xslt documentation and I did not
check it, so look out for typos)
you use it like this $result = $base power $power:
<xsl:variable name="result">
<xsl:call-template name="power">
<xsl:with-param name="base">
<xsl:value-of select="$base"/>
</xsl:with-param>
<xsl:with-param name="power">
<xsl:value-of select="$power"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
Cu,
Goetz.
PGP signature
- References:
- power
- From: SoftLiban ITANI Mohamed