这是我的示例XML看起来像
<Header>
<id> 1234 <id>
<type> abcd <type>
<account>
<code1>a11 </code1>
<code2>a12 </code2>
<expense>
<cost> 10 </cost>
<description> Travel </description>
</expense>
<expense>
<cost> 30 </cost>
<description> Travel </description>
</expense>
<expense>
<cost> 20 </cost>
<description> Hotel </description>
</expense>
<expense>
<cost> 10 </cost>
<description> Hotel </description>
</expense>
</account>
</Header>
我需要以XML格式显示结果,如下所示
<Header>
<id> 1234 <id>
<type> abcd <type>
<code1>a11 </code1>
<code2>a12 </code2>
<description> Travel </description>
<cost> 40 </cost> <!-- sum of cost nodes, if description is Travel -->
<description> Hotel </description>
<cost> 30 </cost> <!-- sum of cost nodes, if description is Hotel -->
</Header>
如何根据条件在XSLT 2.0中编写成本总和?
答案 0 :(得分:0)
<xsl:template match="Header/account">
...
<cost><xsl:value-of select="sum(expense[contains(description, 'Travel')]/cost)"/></cost>
...
<cost><xsl:value-of select="sum(expense[contains(description, 'Hotel')]/cost)"/></cost>
</xsl:template>
应该这样做,添加我放置...
的其他元素。