home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / XML Utilities / Professional Programmer XSL IDE / Xselerator25.msi / Data.Cab / F35328_pow.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-03-16  |  1.6 KB  |  58 lines

  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  2.  xmlns:saxon="http://icl.com/saxon"
  3.  xmlns:myMultiply="f:myMultiply" 
  4.  exclude-result-prefixes="xsl saxon myMultiply"
  5.  >
  6.  
  7.   <xsl:import href="curry.xsl"/> 
  8.   <xsl:import href="iter.xsl"/>
  9.  
  10.   <myMultiply:myMultiply/>
  11.  
  12.   <!-- This template implements the following general power fn:
  13.   
  14.     > power :: (Ord a, Num a, Num b) => a -> b -> b
  15.     > power n x = iter n (multByX x) 1
  16.     
  17.     where
  18.     > multByX :: Num a => a -> a -> a
  19.     > multByX x y = (*x) y
  20.     
  21.     Note the use of the partial application in multByX !
  22.     
  23.     -->
  24.   
  25.   <xsl:template name="pow">
  26.     <xsl:param name="pTimes" select="0"/>
  27.     <xsl:param name="pX"/>
  28.     
  29.     <xsl:variable name="vMultiply" select="document('')/*/myMultiply:*[1]"/>
  30.     
  31.     <xsl:variable name="vrtfCurriedMultByX">
  32.       <xsl:call-template name="curry">
  33.         <xsl:with-param name="pFun" select="$vMultiply"/>
  34.         <xsl:with-param name="pNargs" select="2"/>
  35.       <xsl:with-param name="arg2" select="$pX"/>
  36.       </xsl:call-template>
  37.     </xsl:variable>
  38.     
  39.     <xsl:variable name="vCurriedMultByX" 
  40.                   select="saxon:node-set($vrtfCurriedMultByX)/node()"/>
  41.     
  42.     <xsl:call-template name="iter">
  43.       <xsl:with-param name="pTimes" select="$pTimes"/>
  44.       <xsl:with-param name="pFun" select="$vCurriedMultByX"/>
  45.       <xsl:with-param name="pX" select="1"/>
  46.     </xsl:call-template>
  47.     
  48.   </xsl:template>
  49.  
  50.   
  51.   <xsl:template match="myMultiply:*">
  52.     <xsl:param name="arg1"/>
  53.     <xsl:param name="arg2"/>
  54.   
  55.     <xsl:value-of select="$arg1 * $arg2"/>
  56.   </xsl:template>
  57.  
  58. </xsl:stylesheet>