How to Test Numeric Value in XSL Style Sheet
May 28th, 2008 by Andrew Chen
I was doing some experiment on my own to try to format an XML file into HTML
To convert a string to number you can use the number function like this
You may use XPath expression in places of the variable. When the variable is not a numeric value fuction number($variable) returns nothing. When NOTHING is converted to a string it has a string value of “NaN”
To convert a value to string you can use the following function
So to test whether the first 10 characters of a string is number you can use the following code
<xsl:if test=”string(number(substring($variable,1,10)))!=’NaN’”>
THE FIRST 10 CHARACTERS IS INDEED NUMBERS
</xsl:if>


Great Answer. It worked perfectly.