Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Convert String to Integer in XSLT 1.0

Tags:

string

int

xslt

I want to convert a string value in xslt to an integer value. I am using xslt 1.0, so i can't use those functions supported in xslt 2.0. Please help.

like image 434
Kapil Avatar asked Aug 12 '09 12:08

Kapil


People also ask

How to convert string to integer in XSLT?

XSLT 1.0 does not have an integer data type, only double. You can use number() to convert a string to a number.

What is number () in XSLT?

Definition and Usage. The <xsl:number> element is used to determine the integer position of the current node in the source. It is also used to format a number.

How do I replace in XSLT?

With the help of the XSLT2. 0 replace () function removes undesired characters from a string in powerful regular expressions. XSLT replaces corresponding single characters, not the entire string.


2 Answers

Adding to jelovirt's answer, you can use number() to convert the value to a number, then round(), floor(), or ceiling() to get a whole integer.

Example

<xsl:variable name="MyValAsText" select="'5.14'"/> <xsl:value-of select="number($MyValAsText) * 2"/> <!-- This outputs 10.28 --> <xsl:value-of select="floor($MyValAsText)"/> <!-- outputs 5 --> <xsl:value-of select="ceiling($MyValAsText)"/> <!-- outputs 6 --> <xsl:value-of select="round($MyValAsText)"/> <!-- outputs 5 --> 
like image 139
jeffreypriebe Avatar answered Oct 17 '22 02:10

jeffreypriebe


XSLT 1.0 does not have an integer data type, only double. You can use number() to convert a string to a number.

like image 27
jelovirt Avatar answered Oct 17 '22 02:10

jelovirt