Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Adding a zero to a string using "current()" in "format-number"

Jesper!Oct 8 2019 — edited Oct 9 2019

Hi Oracle friends,

I have an xml element <RandomNumber> which string size is always either 8 or 9 digits. If the element has a string-length greater than 1, I wish to left pad it with a zero if its size is 8 instead of 9 digits. So I wrote the following code:

<?xml version = '1.0' encoding = 'UTF-8'?>

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

    <xsl:output method="xml"/>

    <xsl:variable name="STRING_LENGTH">

          <xsl:text>1</xsl:text>

    </xsl:variable>

    <xsl:for-each select="current()[string-length(RandomNumber) >= $STRING_LENGTH]/RandomNumber">

        <xsl:element name="leftPNumber">

            <xsl:value-of select="format-number(current(), '000000000')"/>

        </xsl:element>

    </xsl:for-each>

    </xsl:stylesheet>

For the input:

<RandomNumbers> <RandomNumber>11223366</RandomNumber> </RandomNumbers>

The intended output should be:

<leftPNumber>011223366</leftPNumber>

For some reason it doesnt work as intended, but doesnt fault either. It just creates the new element with the original number in it, without adding the additional "0". Is this because im using current() inside the "format-number"? If so, what alternative can I use?

Cheers,

Jesper

This post has been answered by Martien van den Akker on Oct 8 2019
Jump to Answer
Comments
Post Details
Added on Oct 8 2019
2 comments
2,835 views