EXSLT - math:power - XSLT Template Implementation

Supported Version: 1
XML Definition: math.power.xml
Source: math.power.template.xsl

Source

<xsl:template name="math:power">
   <xsl:param name="base"
              select="0" />
   <xsl:param name="power"
              select="1" />
   <xsl:choose>
      <xsl:when test="$power &lt; 0 or contains(string($power), '.')">
         <xsl:message terminate="yes">
        The XSLT template math:power doesn't support negative or
        fractional arguments.
      </xsl:message>
         <xsl:text>NaN</xsl:text>
      </xsl:when>
      <xsl:otherwise>
         <xsl:call-template name="math:_power">
            <xsl:with-param name="base"
                            select="$base" />
            <xsl:with-param name="power"
                            select="$power" />
            <xsl:with-param name="result"
                            select="1" />
         </xsl:call-template>
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>
<xsl:template name="math:_power">
   <xsl:param name="base"
              select="0" />
   <xsl:param name="power"
              select="1" />
   <xsl:param name="result"
              select="1" />
   <xsl:choose>
      <xsl:when test="$power = 0">
         <xsl:value-of select="$result" />
      </xsl:when>
      <xsl:otherwise>
         <xsl:call-template name="math:_power">
            <xsl:with-param name="base"
                            select="$base" />
            <xsl:with-param name="power"
                            select="$power - 1" />
            <xsl:with-param name="result"
                            select="$result * $base" />
         </xsl:call-template>
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>

Change History

Submitted: 2001-05-22
Creator: Jeni Tennison(http://www.jenitennison.com)

Returns the result of raising a number to the power.
VersionModifiedByDetails
1.12002-08-21Craig Stewart

Added 4XSLT and libxslt implementation to the list.

1.22002-11-12Craig Stewart

Updated 4XSLT version to 0.12.0a3.

1.32003-03-03Craig Stewart

Fixed a bug in the implementations, MSXSL is now correctly listed as the langauge used by math.power.msxsl.xsl

http://www.exslt.org/math/functions/power/math.power.template.xsl.html last modified 2003-03-03