• Status: Solved
  • Priority: Low
  • Security: Public
  • Views: 194
  • Last Modified:

xslt 1.0 - Formatting string (Removing leading zeros)

Hi guys,

I am facing an issue with string formatting to remove leading zeros.

when
input = '000111100' or 111100
result is: 111100  - all ok!

when
input = '01111111111111111111101110'
result is: "1111111111111111100000000"
expected result is: 1111111111111111111101110

Function
<xsl:variable name="test1" select="string(number($input))" />

Open in new window

It looks like does not work for large numbers.
Please share if you have an explanation or logic function to remove leading zeros only on any size of value.

Thank You,
Darius
0
Darius
Asked:
Darius
  • 3
1 Solution
 
Geert BormansInformation ArchitectCommented:
The problem is that a number in XSLT1 can't grow that big

you would better treath this as a string and chop the 0 off one by one in a recursive template

    <xsl:template name="cut-leading-zeros">
        <xsl:param name="str"/>
        <xsl:choose>
            <xsl:when test="substring($str, 1, 1) = '0'">
                <xsl:call-template name="cut-leading-zeros">
                    <xsl:with-param name="str" select="substring($str, 2)"/>
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="$str"/>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    

Open in new window

0
 
Geert BormansInformation ArchitectCommented:
<xsl:variable name="test1" select="string(number($input))" />

Open in new window


would then become

<xsl:variable name="test1">
            <xsl:call-template name="cut-leading-zeros">
                <xsl:with-param name="str" select="$input"></xsl:with-param>
            </xsl:call-template>
</xsl:variable>

Open in new window

0
 
DariusAuthor Commented:
Thank you Geert,

much appreciate
0
 
Geert BormansInformation ArchitectCommented:
welcome
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now