XSLT 添加不存在的节点 [英] XSLT add not existing nodes
本文介绍了XSLT 添加不存在的节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个这样的 XML 片段
I have an XML fragment like this
<lines>
<item><code>1.1</code><amt>1000.00</amt></item>
<item><code>1.3.1</code><amt>2000.00</amt></item>
<item><code>1.3.2</code><amt>3000.00</amt></item>
<item><code>2.1</code><amt>4000.00</amt></item>
...
</lines>
我想对所有 1* 节点求和.完整列表是已知的,所以我可以写一些类似的东西:
I want to make a sum of all 1* nodes. The full list is known so I can write something like:
<xsl:value-of select="item[code=1.1]/amt +
item[code=1.2]/amt + item[code=1.3.1]/amt + item[code=1.3.2]/amt"/>
问题是这些节点中的任何一个(甚至所有)都可能不存在(例如示例中的 1.2).所以语句返回 NaN !
The issue is that any (even all) of those nodes can be absent (like 1.2 in the example). So the statement returns NaN !
希望得到一些好的建议:)
Would appreciate some good advise :)
亚历克斯
推荐答案
在这种情况下,因为它是一个直和你可以做
In this case since it's a straight sum you could just do
<xsl:value-of select="sum(item[code=1.1 or code=1.2 or
code=1.3.1 or code=1.3.2]/amt)"/>
这篇关于XSLT 添加不存在的节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文