[英]XSLT 1.0 Muenchian Grouping
我一直在使用 Muenchian 组方法处理一些示例,现在有一个工作,其中通过键和求和值是同一父节点中的兄弟姐妹,但现在我正在查看 XML 输入,其中结构略有不同.
这是我的输入
<?xml version="1.0" encoding="UTF-8"?>
<ArrayList>
<Item>
<amounts>
<amount>1000.00</amount>
</amounts>
<invoice>
<customerId>1234</customerId>
</invoice>
</Item>
<Item>
<amounts>
<amount>1500.00</amount>
</amounts>
<invoice>
<customerId>7755</customerId>
</invoice>
</Item>
<Item>
<amounts>
<amount>800.00</amount>
</amounts>
<invoice>
<customerId>1018</customerId>
</invoice>
</Item>
</ArrayList>
我想去
<?xml version="1.0" encoding="UTF-8"?>
<customers>
<customer>
<customerID>1234</customerID>
<totalAmount>1800</totalAmount>
</customer>
<customer>
<customerID>7755</customerID>
<totalAmount>1500</totalAmount>
</customer>
</customers>
最初,我得到了我独特的 customerId 的确定,但总量为 0.00,现在玩它这么久,我的 XSL 不再有效。 我试图避免发布此问题,直到我设法解决它,但我现在对此视而不见,无法发现问题。 即使我已经排序,我知道它不会给我我想要的。
这是我的 XSL:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" />
<xsl:key name="group" match="Item" use="invoice/customerId" />
<xsl:template match="ArrayList">
<customers>
<xsl:apply-templates select="Item[generate-id() = generate-id(key('group', invoice/customerId[1])]"/>
</customers>
</xsl:template>
<xsl:template match="Item">
<customer>
<xsl:copy-of select="customerID"/>
<totalAmount><xsl:value-of select="sum(key('group', invoice/customerId)/amounts/amount)" /></totalAmount>
</customer>
</xsl:template>
</xsl:stylesheet>
谢谢
apply-templates 表达式中缺少 close )
,使<xsl:apply-templates select="Item[generate-id() = generate-id(key('group', invoice/customerId[1]))]"/>
.
另一方面,我在 Twitter 上建议的 Muenchian 分组将是<xsl:apply-templates select="Item[generate-id() = generate-id(key('group', invoice/customerId)[1])]"/>
.
最后,在您想要的Item
元素的上下文中,例如<xsl:copy-of select="invoice/customerId"/>
而不是<xsl:copy-of select="customerID"/>
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.