我有以下XML:
<root>
<groups>
<group id="101">
<number>10</number>
<children>
<leader id = "A" />
<members>
<member id="1">
<member id="2">
<member id="3">
</members>
</children>
</group>
<group id="102">
<number>20</number>
<children>
<leader id = "A" />
<members>
<member id="4">
<member id="5">
<member id="3">
</members>
</children>
</group>
<group id="103">
<number>30</number>
<children>
<leader id = "A" />
<members>
<member id="1">
<member id="4">
<member id="3">
</members>
</children>
</group>
</groups>
</root>
如何使用XSL对所有id = 1的成员的属性进行求和?
由于
答案 0 :(得分:6)
使用强>:
sum(/*/*/*/number[../children/members/member[@id=1]])
这种转变:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:value-of select=
"sum(/*/*/*/number
[../children/members/member[@id=1]])
"/>
</xsl:template>
</xsl:stylesheet>
应用于此XML文档(更正了严重格式错误的文本!):
<root>
<groups>
<group id="101">
<number>10</number>
<children>
<leader id = "A" />
<members>
<member id="1"/>
<member id="2"/>
<member id="3"/>
</members>
</children>
</group>
<group id="102">
<number>20</number>
<children>
<leader id = "A" />
<members>
<member id="4"/>
<member id="5"/>
<member id="3"/>
</members>
</children>
</group>
<group id="103">
<number>30</number>
<children>
<leader id = "A" />
<members>
<member id="1"/>
<member id="4"/>
<member id="3"/>
</members>
</children>
</group>
</groups>
</root>
生成想要的正确结果:
40