Xml 在XSLT2.0中,我一直在尝试计算总和(数量)*价格
首先,我的任务是按ProviderName对元素进行分组,按@ItemNumber求和数量,然后计算总数=数量*价格。我无法进行此计算,我会出错。这就是我到现在为止所做的。任何帮助都将不胜感激Xml 在XSLT2.0中,我一直在尝试计算总和(数量)*价格,xml,xslt,Xml,Xslt,首先,我的任务是按ProviderName对元素进行分组,按@ItemNumber求和数量,然后计算总数=数量*价格。我无法进行此计算,我会出错。这就是我到现在为止所做的。任何帮助都将不胜感激 <?xml version="1.0"?> <Items> <Item ItemNumber="1148089"> <ProductName>Plexi Leather-Silver-Black&l
<?xml version="1.0"?>
<Items>
<Item ItemNumber="1148089">
<ProductName>Plexi Leather-Silver-Black</ProductName>
<ProviderName>Vestal Watches</ProviderName>
<Quantity>1</Quantity>
<Price>189.99</Price>
</Item>
<Item ItemNumber="1251465">
<ProductName>Cherub Baby Bottle Kit - Berry</ProductName>
<ProviderName>Cherub Baby</ProviderName>
<Quantity>3</Quantity>
<Price>42.99</Price>
</Item>
<Item ItemNumber="1351468">
<ProductName>M ES MOC OX BITTER CHOCOLATE</ProductName>
<ProviderName>Rockport</ProviderName>
<Quantity>7</Quantity>
<Price>72.99</Price>
</Item>
<Item ItemNumber="1151464">
<ProductName>Spritz Grape Seat and Extra Seat</ProductName>
<ProviderName>Bambeano</ProviderName>
<Quantity>1</Quantity>
<Price>56.99</Price>
</Item>
<Item ItemNumber="1251464">
<ProductName>Apple Pattern T-Shirt-Blue</ProductName>
<ProviderName>Avahna</ProviderName>
<Quantity>1</Quantity>
<Price>14.99</Price>
</Item>
<Item ItemNumber="1351464">
<ProductName>W ZANA BIKE FRONT OXFORD SATIN NICKEL</ProductName>
<ProviderName>Rockport</ProviderName>
<Quantity>1</Quantity>
<Price>59.99</Price>
</Item>
<Item ItemNumber="1251464">
<ProductName>Cherub Baby Bottle Kit - Citrus</ProductName>
<ProviderName>Cherub Baby</ProviderName>
<Quantity>1</Quantity>
<Price>42.99</Price>
</Item>
</Items>
树脂皮革银黑色
维斯塔尔手表
1.
189.99
Cherub婴儿奶瓶套件-浆果
天使宝贝
3.
42.99
我是MOC OX苦巧克力
洛克波特
7.
72.99
Spritz葡萄座椅和额外座椅
班比亚诺
1.
56.99
苹果图案T恤-蓝色
阿瓦纳
1.
14.99
W ZANA自行车正面牛津缎面镍
洛克波特
1.
59.99
Cherub婴儿奶瓶套件-柑橘
天使宝贝
1.
42.99
这是我的XSLT
<xsl:stylesheet version="2.0"
xmlns:ex="http://exslt.org/common"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="Items">
<!-- TODO: Auto-generated template -->
<html>
<head>
<link rel="stylesheet" type="text/css" href="Item.css" />
<title>Sales Amount by Provider</title>
</head>
<body>
<h1>Sales Amount by Provider</h1>
<table>
<xsl:for-each-group select="Item" group-by="ProviderName">
<xsl:sort select="ProviderName"/>
<tr>
<th colspan="4">Provider: <xsl:value-of select="ProviderName"/></th>
</tr>
<tr id="title">
<th>Item Number</th>
<th>Quantity</th>
<th>Unit Price </th>
<th>Total</th>
</tr>
<xsl:for-each-group select="current-group()" group-adjacent="@ItemNumber">
<xsl:sort select="@ItemNumber"/>
<tr>
<td>
<xsl:value-of select="distinct-values(current-group()/@ItemNumber)"/>
</td>
<td>
<xsl:value-of select="sum(current-group()/Quantity)"/>
</td>
<td>
<xsl:value-of select="distinct-values(current-group()/Price)"/>
</td>
<td>
<xsl:variable name="total">
<xsl:for-each select="current-group()/Item">
<product>
<xsl:value-of select="sum(current-group()/Quantity * current-group()/Price)" />
</product>
</xsl:for-each>
</xsl:variable>
<xsl:value-of select="sum(ex:node-set($total)/product)"/>
</td>
</tr>
</xsl:for-each-group>
<tr>
<th id="SubGrandtotal" colspan="3"><b>Sub-total</b></th>
<!-- <td>
<xsl:value-of select="sum(current-group()/Price)"/> -->
<!-- <xsl:variable name="quantity" select="sum(current-group()/Quantity)" as="xs:double" />
<xsl:variable name="price" select="current-group()/Price/text()" />
<xsl:value-of select="format-number($price*$quantity, '#0.00')"/> -->
<!-- </td> -->
</tr>
</xsl:for-each-group>
<tr>
<th id="SubGrandtotal" colspan="3"><b>Grand-total</b></th>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
按供应商列出的销售额
按供应商列出的销售额
供应商:
项目编号
量
单价
全部的
小计
总计
如果您使用的是XSLT 2.0,那么您可以简单地使用:
<xsl:value-of select="sum(current-group()/(Quantity * Price))" />
对于两个分组级别,以及:
<xsl:value-of select="sum(Item/(Quantity * Price))" />
对于总计。那么,对于发布的代码,您会得到哪些错误?哪些代码行?为什么要尝试在XSLT2.0中使用ex:node set
?