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 / F35508_runningTotal.xsl < prev    next >
Encoding:
Extensible Markup Language  |  2002-01-20  |  2.5 KB  |  80 lines

  1. <xsl:stylesheet version="1.0"
  2. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:saxon="http://icl.com/saxon"
  4. xmlns:myAdd ="f:myAdd"
  5. xmlns:myMult="f:myMult"
  6. >
  7.   <xsl:import href="zipWith.xsl"/>
  8.   <xsl:import href="scanl.xsl"/>
  9.  
  10.   <myAdd:myAdd/>
  11.   <myMult:myMult/>
  12.  
  13.   <xsl:output omit-xml-declaration="yes"/>
  14.   <xsl:template match="/">
  15.     <html>
  16.       <table border="2">
  17.        <tr><th>Title</th><th>Author</th><th>Price</th>
  18.            <th>Sales</th><th>Current Total</th>
  19.        </tr>
  20.        <xsl:call-template name="myRunningTotal">
  21.          <xsl:with-param name="vNodes"
  22.                          select="/booklist/book"/>
  23.        </xsl:call-template>
  24.       </table>
  25.     </html>
  26.   </xsl:template>
  27.   
  28.   <xsl:template name="myRunningTotal">
  29.     <xsl:param name="vNodes" select="/.."/>
  30.     
  31.     <xsl:variable name="vFunAdd" select="document('')/*/myAdd:*[1]"/>
  32.     <xsl:variable name="vFunMult" select="document('')/*/myMult:*[1]"/>
  33.  
  34.     <xsl:variable name="vrtfSingleBookAmounts">
  35.       <xsl:call-template name="zipWith">
  36.         <xsl:with-param name="pFun" select="$vFunMult"/>
  37.         <xsl:with-param name="pList1" select="$vNodes/price"/>
  38.         <xsl:with-param name="pList2" select="$vNodes/sales"/>
  39.       </xsl:call-template>
  40.     </xsl:variable>
  41.     
  42.     <xsl:variable name="vrtfRunningTotal">
  43.       <xsl:call-template name="scanl1">
  44.         <xsl:with-param name="pFun" select="$vFunAdd"/>
  45.         <xsl:with-param name="pList"
  46.                 select="saxon:node-set($vrtfSingleBookAmounts)/*"/>
  47.       </xsl:call-template>
  48.     </xsl:variable>
  49.     
  50.     <xsl:variable name="vRunningTotal"
  51.     select="saxon:node-set($vrtfRunningTotal)/*"/>
  52.     
  53.     <xsl:for-each select="$vNodes">
  54.         <xsl:variable name="vThisPosition" select="position()"/>
  55.         <tr>
  56.            <td><xsl:value-of select="title"/></td>
  57.            <td><xsl:value-of select="price"/></td>
  58.            <td><xsl:value-of select="sales"/></td>
  59.            <td><xsl:value-of select="sales * price"/></td>
  60.            <td><xsl:value-of select="$vRunningTotal
  61.                                          [$vThisPosition]"/>
  62.            </td>
  63.         </tr>
  64.     </xsl:for-each>
  65.   </xsl:template>
  66.   
  67.   <xsl:template match="myAdd:*">
  68.     <xsl:param name="pArg1"/>
  69.     <xsl:param name="pArg2"/>
  70.  
  71.     <xsl:value-of select="$pArg1 + $pArg2"/>
  72.   </xsl:template>
  73.  
  74.   <xsl:template match="myMult:*">
  75.     <xsl:param name="pArg1"/>
  76.     <xsl:param name="pArg2"/>
  77.  
  78.     <xsl:value-of select="$pArg1 * $pArg2"/>
  79.   </xsl:template>
  80. </xsl:stylesheet>