嗨,我对 XSLT 很陌生,所以需要一些关于简单 XSL 代码的帮助。
我的输入 XML
<?xml version="1.0" encoding="ASCII"?>
<Node Name="Person" Received="1" Good="1" Bad="0" Condition="byPerson:1111">
</Node>
<Node Name="Person" Received="1" Good="1" Bad="0" Condition="byPerson:1111">
</Node>
<Node Name="Person" Received="1" Good="1" Bad="0" Condition="byPerson:2222">
</Node>
<Node Name="Person" Received="1" Good="1" Bad="0" Condition="byPerson:2222">
</Node>
<Node Name="Person" Received="1" Good="1" Bad="0" Condition="byPerson:3333">
</Node>
我期望结果是所有 Received ,good 和 Bad 的总和,但每个独特条件只需要添加一次。
像这样的东西
<?xml version="1.0" encoding="ASCII"?>
<Received>3</Received >
<Good>3</Good>
<Bad>0</Bad>
我正在尝试下面的代码,但到目前为止没有成功,只是得到所有东西的总和,只想对每个“条件”求和一次。
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="/">
<xsl:value-of select= "sum(Node@Received)"/>
<xsl:value-of select= "sum(Node/@Good)"/>
<xsl:value-of select= "sum(Node/@Bad)"/>
</xsl:template>