===================================== ===================================如何使用XSLT 1.0計算重複元素的總和
**Input XML:**
<Customers>
<Customer>
<Items>
<Item>
<ItemId>5639</ItemId>
<ProductName> Lawnmower </ProductName>
<Quantity>1</Quantity>
<USPrice>148.95</USPrice>
<Comment>Confirm this is electric</Comment>
</Item>
<Item>
<ItemId>6000</ItemId>
<ProductName>Baby Monitor</ProductName>
<Quantity>2</Quantity>
<USPrice>39.98</USPrice>
<Comment>Confirm this is electric</Comment>
</Item>
</Items>
</Customer>
<Customer>
<Items>
<Item>
<ItemId>7000</ItemId>
<ProductName> Cutter </ProductName>
<Quantity>1</Quantity>
<USPrice>15.95</USPrice>
<Comment>Confirm this is electric</Comment>
</Item>
<Item>
<ItemId>9000</ItemId>
<ProductName> Laptop </ProductName>
<Quantity>5</Quantity>
<USPrice>2048.95</USPrice>
<Comment>Confirm this is electric</Comment>
</Item>
</Items>
</Customer >
輸出XML:
<Customers>
<Customer>
<TotalPurchase>sum(USPRice)</TotalPurchase>
</Customer>
<Customer>
<TotalPurchase>sum(USPrice)</TotalPurchase>
</Customer>
</Customers>
XSLT代碼:
<Customers>
<xsl:for-each select="Customers/Customer">
<Customer>
<xsl:for-each select="Items/Item">
<TotalPurchase>
<xsl:value-of select="sum(/USPrice)"/>
</TotalPurchase>
</xsl:for-each>
</Customer>
</xsl:for-each>
</Customers>
有人可以指導我如何在XSLT 1.0中實現輸出。由於總和功能沒有正常工作。它恢復零。
「*總和功能did not工作*」發佈您的嘗試。請提供一個格式良好的XML作爲輸入示例:「客戶1」不是有效的元素名稱。 –
您是想將現在的價格相加,還是將價格乘以數量? –
感謝您的回覆。 這是我的XSLT代碼。我只需要每個專業人員的項目總和。不是通過乘以數量。 ** XSLT代碼:** <的xsl:for-每個選擇= 「顧客/顧客」> <的xsl:for-每個選擇= 「項目/項目」> < XSL:value-of的選擇= 「SUM(/ USPrice)」/> TotalPurchase> 的xsl:for-each>的 –
ranaa