如何根據另一個值添加值?XSLT根據另一個值添加屬性值
<?xml version="1.0" encoding="UTF-8"?>
<items>
<item id="A1" quantity="5">
<info type="ram x1" import="CA" />
</item>
<item id="A2" quantity="3">
<info type="ram x1" import="SA" />
</item>
<item id="A3" quantity="10">
<info type="ram x2" import="AU" />
</item>
</items>
我需要添加基於所述type
例如我需要的輸出,因爲所有的數量時,
衝壓X1量= 8 RAM X2量= 10
<?xml version="1.0" encoding="UTF-8"?>
<items>
<details type="ram x1" quantity="8"/>
<details type="ram x2" quantity="10"/>
</items>
換試圖每個組首先得到數量,看它是否有效,
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="html" indent="yes" />
<xsl:template match="items">
<xsl:for-each-group select="item" group-by="info/@type">
<xsl:value-of select="sum(@quantity)" />
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>