Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Leadingzeros function in XSLT

Tags:

xslt

Do we have any function for leadingzeros.

like image 438
Sara Avatar asked Sep 13 '11 05:09

Sara


People also ask

How do you remove leading zeros in XML?

Assigned Tags. The field which contains the value with the leading zeroes - if you are sure that this field will always contain a string value (for e.g. 00001234) the just call the parseInt() function and pass the value to this function as parseInt('00001234'); the result will be 1234.

How do you remove leading zeros in xpath?

Convert that into number by using Number() function. - This removes zeros. 2. To remove the leading zeros convert that above result to number by number () function.

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.


1 Answers

Use format-number(12345, "0000000000").

This obviously only works for numbers, and can only pad with zeros, but you can pad with any character using the substring like this:

concat(substring('0000000000',string-length($val)),$val)

This can be useful when padding with .... or spaces, for example, or if your value isn't numeric.

like image 190
Flynn1179 Avatar answered Sep 28 '22 08:09

Flynn1179