问题
<xsl:call-template name="SetNetTemplate">
<xsl:with-param name="xyz" select="$node1value
+ $node2value
+ $node3value
- $node4value
- $node5value
- $node6value"/>
</xsl:call-template>
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"
回答1:
Try it this way:
<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')"/>
EDIT
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.
回答2:
Try
<xsl:with-param name="xyz" select="concat(0, $node1value)
+ concat(0, $node2value)
+ concat(0, $node3value)..."/>
etc
回答3:
For me this worked:
number(concat('0',$nodeValue))
来源:https://stackoverflow.com/questions/22018309/xslt-1-0-how-to-replace-empty-or-blank-value-with-0-zero-in-select-condition