我在这里遇到一些问题,递归运行总计不会为我的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() > 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页面是这样的:
非常感谢您的帮助
答案 0 :(得分: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>
答案 1 :(得分:0)
可以使用FXSL的scanl
模板/功能 - 如下所示:Is it possible to keep a count in a for-each loop in xslt
另见:
http://www.oxygenxml.com/archives/xsl-list/200312/msg00322.html