我使用递归函数来计算每个发票和每个客户的计算列的总数(价格 * 数量)。现在我需要计算每个客户的所有发票和所有客户的所有发票的总数。
xml 看起来像这样:
  <cinvoices>
        <client> (with information @ client) </client>
            <invoices>
                <products>
                    <product> (information @ product: name, type ect and..
                        <price>123</price>
                        <quantity>21</quantity>
                    </product>
                    <product> (information @ product: name, type ect and..
                        <price>123</price>
                       <quantity>11</quantity>
                   </product>
                </products>
           <invoices>
               <products>
                    <product> (information @ product: name, type ect and..
                    <price>32</price>
                    <quantity>3</quantity>
               </product>
               <product> (information @ product: name, type ect and..
                    <price>12</price>
                    <quantity>9</quantity>
               </product>
           </products>
       </invoices>
    </client>
    <client>
      <same as above>
    </client>
    </cinvoices>
xslt 中使用的函数是:
<xsl:template name="sumProducts"> 
        <xsl:param name="pList"/> 
        <xsl:param name="pRunningTotal" select="0"/>         
        <xsl:choose> 
            <xsl:when test="$pList"> 
                <xsl:variable name="varMapPath" select="$pList[1]"/> 
                <xsl:call-template name="sumProducts"> 
                    <xsl:with-param name="pList" select="$pList[position() > 1]"/> 
                    <xsl:with-param name="pRunningTotal" 
                    select="$pRunningTotal + $varMapPath/price *    $varMapPath/quantity"/>                    
                </xsl:call-template> 
            </xsl:when> 
            <xsl:otherwise> 
                $<xsl:value-of select="format-number($pRunningTotal, '#,##0.00')"/> 
            </xsl:otherwise>  
        </xsl:choose> 
              </xsl:template>
===================== 函数调用如下:
  <xsl:call-template name="sumProducts"> 
                             <xsl:with-param name="pList" select="*/*"/> 
                             </xsl:call-template> 
知道如何使用此功能计算每个客户的发票总额以及所有客户和所有发票的总额。
谢谢你。