xslt 1.0 如何在选择条件下用 0(零)替换空值或空白值 [英] xslt 1.0 how to replace empty or blank value with 0 (zero) in select condition
本文介绍了xslt 1.0 如何在选择条件下用 0(零)替换空值或空白值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
<xsl:call-template name="SetNetTemplate">
<xsl:with-param name="xyz" select="$node1value
+ $node2value
+ $node3value
- $node4value
- $node5value
- $node6value"/>
</xsl:call-template>
如果 nodevalue 为空或空白,我想用 0(零)替换该值.问题是在这个计算中,如果任何节点值为空或空白,它会给出 NaN 结果.例如选择10-2+5-2- -4"
If nodevalue is empty or blank, i want to replace that value with 0 (zero). Problem is that in this calculation if any nodevalue is empty or blank, it is giving NaN result. e.g. select "10-2+5-2- -4"
推荐答案
试试看:
<xsl:with-param name="xyz" select="translate(number($node1value), 'aN', '0')
+ translate(number($node2value), 'aN', '0')
+ translate(number($node3value), 'aN', '0')
...
- translate(number($node6value), 'aN', '0')"/>
<小时>
编辑
请注意,以上只是一个可爱的技巧",旨在避免执行此操作的正确且直接的解决方案的冗长:
Note that the above is just a "cute trick" designed to avoid the verbosity of the proper and straightforward solution that would do this:
<xsl:choose>
<xsl:when test="number($node1value)">
<xsl:value-of select="$node1value" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="0" />
</xsl:otherwise>
</xsl:choose>
在尝试将它们视为数字之前,先对每个操作数进行处理.
to each and every one of your operands before trying to treat them as numbers.
这篇关于xslt 1.0 如何在选择条件下用 0(零)替换空值或空白值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文