Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Padding Zeros in XSLT

Tags:

padding

xslt

Is there any function that pads zeros on the left?

The requirements of what I'm trying to do are:

  • We don't know the coming input string length.
  • If it is less than 20 we have to pad zeros on the left side.
  • If the input string length is 10 then we have to pad 10 zeros in the left side.

Example

Input:

1234567899

Output:

00000000001234567899

like image 373
sum Avatar asked Apr 01 '13 14:04

sum


People also ask

How to pad a numeric value with leading zeros?

To pad a numeric value with leading zeros to a specific length. Determine how many digits to the left of the decimal you want the string representation of the number to have. Include any leading zeros in this total number of digits. Define a custom numeric format string that uses the zero placeholder "0" to represent the minimum number of zeros.

Is there any function that pads zeros on the left?

Is there any function that pads zeros on the left? We don't know the coming input string length. If it is less than 20 we have to pad zeros on the left side. If the input string length is 10 then we have to pad 10 zeros in the left side.

How to add leading zeros to the length of a string?

Determine the length of the unpadded numeric string by calling the integer value's ToString ("D").Length or ToString ("X").Length method. Add the number of leading zeros that you want to include in the formatted string to the length of the unpadded numeric string. Adding the number of leading zeros defines the total length of the padded string.

How many zeros in the left side of the string?

We don't know the coming input string length. If it is less than 20 we have to pad zeros on the left side. If the input string length is 10 then we have to pad 10 zeros in the left side. Show activity on this post.


1 Answers

format-number function can be used for this:

<xsl:value-of select="format-number(1234567899, '00000000000000000000')" />
like image 120
randag Avatar answered Oct 27 '22 04:10

randag