2013-05-09 82 views
0

林XSL计算领域,递归运行总计不低于我的XSL模板加起来是我的XSL代码和XML运行这里有一些问题,总

XML:

</xsl:for-each-group> 
      Subtotal: 
      <td> 
      <xsl:for-each-group select="current-group()" group by="@ItemNumber"> 
      <xsl:sort select="current-grouping-key()"/> 
      <xsl:call-template name="count_subtotal"> 
      <xsl:with-param name="cur_grp_qty" select="sum(current-group()/Quantity)"/> 
      <xsl:with-param name="cur_grp_up" select="distinct-values(current-group()/UnitPrice)"/> 
      </xsl:call-template> 
       </xsl:for-each-group> 
    </xsl:for-each-group> 


<xsl:template name="count_subtotal"> 
     <xsl:param name="total" select="0"/> 
     <xsl:param name="cur_grp_qty"/> 
     <xsl:param name="cur_grp_up"/> 
     <xsl:choose> 
     <xsl:when test="$cur_grp_qty"> 
      <xsl:variable name="first_total" select="$cur_grp_qty[1]*$cur_grp_up[1]"/> 
      <xsl:call-template name="count_subtotal"> 
       <xsl:with-param name="cur_grp_qty" select="$cur_grp_qty[position() &gt; 1]"/> 
       <xsl:with-param name="total" select="$first_total+$total"/> 
      </xsl:call-template> 
     </xsl:when> 
     <xsl:otherwise> 
      <xsl:value-of select="round($total)"/> 
     </xsl:otherwise> 
     </xsl:choose> 
    </xsl:template> 

这是XML文件:

<Items> 
    <Item ItemNumber="1"> 
     <ProductName>c</ProductName> 
     <ProviderName>c</ProviderName> 
     <Quantity>2</Quantity> 
     <UnitPrice>39</UnitPrice> 
    </Item> 
    <Item ItemNumber="2"> 
     <ProductName>b</ProductName> 
     <ProviderName>b</ProviderName> 
     <Quantity>1</Quantity> 
     <UnitPrice>3</UnitPrice> 
     </Item> 
     <Item ItemNumber="3"> 
     <ProductName>abt</ProductName> 
     <ProviderName>bd</ProviderName> 
     <Quantity>1</Quantity> 
     <UnitPrice>12</UnitPrice> 
     </Item> 
     <Item ItemNumber="4"> 
     <ProductName>a</ProductName> 
     <ProviderName>a</ProviderName> 
     <Quantity>1</Quantity> 
     <UnitPrice>3</UnitPrice> 
     </Item> 
     <Item ItemNumber="5"> 
     <ProductName>ab</ProductName> 
     <ProviderName>cd</ProviderName> 
     <Quantity>2</Quantity> 
     <UnitPrice>1</UnitPrice> 
     </Item> 
     <Item ItemNumber="6"> 
     <ProductName>sdf</ProductName> 
     <ProviderName>bfd</ProviderName> 
     <Quantity>1</Quantity> 
     <UnitPrice>12</UnitPrice> 
     </Item> 

的欲望和html页面是这样的:

enter image description here 您的帮助将不胜感激

+0

PLS。分享完整XSLT – 2013-05-09 07:05:54

+0

@NavinRawat,文件有点大,对不起,我不认为我可以在这里分享,你需要知道更多的信息? – danial 2013-05-09 08:05:33

回答

0

无论如何,我已经创建了新的XSLT来生成输出。看一看:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 

    <xsl:output indent="yes"/> 

    <xsl:template match="/"> 
    <html> 
     <head/> 
     <body> 
     <table> 
      <thead> 
      <tr> 
       <th> 
       <xsl:text>Item Number</xsl:text> 
       </th> 
       <th> 
       <xsl:text>Quantity</xsl:text> 
       </th> 
       <th> 
       <xsl:text>Unit Price</xsl:text> 
       </th> 
       <th> 
       <xsl:text>Total</xsl:text> 
       </th> 
      </tr> 
      </thead> 
      <tbody> 
      <xsl:for-each select="//Item"> 
       <tr> 
       <td> 
        <xsl:value-of select="ProductName"/> 
       </td> 
       <td> 
        <xsl:value-of select="Quantity"/> 
       </td> 
       <td> 
        <xsl:value-of select="UnitPrice"/> 
       </td> 
       <td> 
        <xsl:value-of select="sum(Quantity * UnitPrice)"/> 
       </td> 
       </tr> 
      </xsl:for-each> 
      <tr colspan="3"> 
       <xsl:value-of select="sum(for $x in //Item return ($x/Quantity * $x/UnitPrice))"/> 
      </tr> 
      </tbody> 
     </table> 
     </body> 
    </html> 
    </xsl:template> 

</xsl:stylesheet>