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
DariusAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Gertone (Geert Bormans)Information 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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Gertone (Geert Bormans)Information 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
Gertone (Geert Bormans)Information ArchitectCommented:
welcome
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.