How To Test For NaN In XSLT



TODO:

Have you ever wanted to test for NaN in XSLT?

 

SOLUTION:

<xsl:variable name="My_Variable">
     <xsl:choose>
          <xsl:when test="string(number($root/mynode))='NaN'"></xsl:when>
     <xsl:otherwise>
           <xsl:value-of select="number(string($root/mynode))" />
     </xsl:otherwise>
     </xsl:choose>
</xsl:variable>

 

NOTES:

This snippet will test for NaN.  If found, it assigns empty string to the variable, and if it is not found it just uses the node value.  Then you just use this variable later and all is well.



Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading