I. XSLT 1.0 :
No xs: integer and xs: decimal in the XPath 1.0 data model used by XSLT 1.0.
Here is a snippet of code that you can use :
<xsl:choose> <xsl:when test="not(floor(SAVG) = SAVG)"> <xsl:value-of select="format-number(SAVG, '###,###,##0.00#')"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="SAVG"/> </xsl:otherwise> </xsl:choose>
Pay attention . To check if a numeric value is an integer, we use the following test:
floor($someNum) = $someNum
Here is one way to do this:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:sequence select= "for $num in (3, 3.14) return if($num instance of xs:integer) then ($num, ' is xs:integer', '
') else if($num instance of xs:decimal) then ($num, ' is xs:decimal', '
') else ($num, ' is something else', '
') "/> </xsl:template> </xsl:stylesheet>
when this conversion is applied to any XML document (not used), the desired, correct result is obtained :
3 is xs:integer 3.14 is xs:decimal
Or using the format-number() function according to your example :
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xsl:output method="text"/> <xsl:template match="/"> <xsl:sequence select= "for $num in (3, 3.14) return if($num instance of xs:integer) then (format-number($num, '###,###,##0.###'), '
') else if($num instance of xs:decimal) then (format-number($num, '###,###,##0.00#'), '
') else () "/> </xsl:template> </xsl:stylesheet>
produces
3 3.14