0
谢谢大家花时间查看我的问题。XSLT函数sum()不计算节点
当节点值不同时总结节点时遇到问题,但如果它是相同的,则工作。
这里是我的XML -
<statement>
<agency>
<employerShareAmt>75.00</employerShareAmt>
</agency>
<agency>
<employerShareAmt>76.00</employerShareAmt>
</agency>
</statement>
这里是我的XSLT -
<xsl:template match="/">
<root>
<xsl:call-template name="shopData"/>
</root>
</xsl:template>
<xsl:template name="shopData">
<RESULT>
<xsl:call-template name="sum"/>
</RESULT>
</xsl:template>
<xsl:template match="node()|@*" name="sum">
<xsl:apply-templates select="node()|@*"/>
</xsl:template>
<xsl:template match="statement">
<agency>
<xsl:for-each-group select="agency"
group-by="employerShareAmt">
<employerShareAmt>
<xsl:value-of
select="sum(current-group()/employerShareAmt)"/>
</employerShareAmt>
</xsl:for-each-group>
</agency>
</xsl:template>
结果是75 76。但是,如果这两个分别为75,其结果将是150
我似乎认为它是按值分组然后添加它们。我怎样才能得到它的节点,所以上述XML结果将是151?
这听起来像你只是想要所有'employerShareAmt'值的总和?在这种情况下,你可以忘记分组。除非有多个代理机构,并且您希望每个代理机构的总数?但是你按照份额的价值分组,并且这是不对的。真实数据中是否有某种代理ID? – Borodin