|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: power
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.
Attachment:
pgp00006.pgp
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








