2013-05-09 2 views
0

Im имея некоторые проблемы здесь, рекурсия нарастающим итогом не складывает для моего шаблона XSL ниже код для моего XSL и XMLXSL вычисляемое поле для запуска полного

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. share complete XSLT –

+0

@NavinRawat, документ очень большой, извините, я не думаю, что могу поделиться им здесь, вам нужно больше узнать информацию? – danial

ответ

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> 
Смежные вопросы