XSLT: How to convert NaN (Not a Number) to zero

Are you using XSLT to render pages in Sense/Net? I'm sure you have already seen NaN when you wanted to work with numbers.
NaN is a value of numeric data type representing an undefined or unrepresentable value.
This could happen, for example, when you're trying to access the value of a Number Field of an unset referenced Content.

If you still want to use some value instead of NaN then you may find this piece of code useful:
[code:xml]<xsl:variable name="priceOfBooks" select="sum(Fields/Price)" />
<xsl:variable name="TotalPriceOfBooks">
    <xsl:when test="string(number($priceOfBooks))='NaN'">0</xsl:when>
      <xsl:value-of select="$priceOfBooks" />

<xsl:value-of select="format-number($TotalPriceOfBooks, '$#,###.00')"/>[/code]

Comments are closed

Welcome to the blog!

Sense/Net ECM is ever evolving. Community means the world to us so we want to keep you apprised on what’s happening on our side of the woods. Want to make us happy? Add a comment and tell us what you think!

Month List