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