Subscribe to
Posts
Comments

I was doing some experiment on my own to try to format an XML file into HTML

result using an XSL style sheet and I encountered the case where I needed to test whether the first 10 characters of a variable is numbers. I didn’t know how to do that and did some research. There are functions available in XSL style sheet you can use to convert string to number and convert numbers to string.

To convert a string to number you can use the number function like this

number($variable)

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

string($variable)

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>


Related Posts:

  • A Tip to Help with Tax Deduction
  • VB Script to Rename All Files in a Folder
  • With 688.7 Billion Cash, It May be the Most Under Valued Company
  • Batch Script on Windows: Using For Loop to Rename All Files in a Folder
  • Filegroup


  • 1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
    Loading ... Loading ...

    RSS feed | Trackback URI

    1 Comment »

    Comment by Uday, Austin, TX
    2010-08-04 14:33:27
    MyAvatars 0.2

    Great Answer. It worked perfectly.

     
    Name (required)
    E-mail (required - never shown publicly)
    URI
    Subscribe to comments via email
    Your Comment (smaller size | larger size)
    You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.