cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in XSL mapping with leading zero's

Former Member
0 Kudos

Hi ,

i am facing a problem in disigning a XSL mapping where one of the source field (type string ) ,and I need to remove the leading zero's to map it to target.

we have format-numer ,but It is not working in this case ,may be because of type string.

and the replace command is not supported .

So can any one suggest me some way to resolve this xsl problem.

Thanks,

Raju.

Accepted Solutions (1)

Accepted Solutions (1)

0 Kudos

Do you want to remove all the leading zero's, or till 20-digital?

Former Member
0 Kudos

I want to remove all the leading zero's

i.e

if the string is like ...00000235 ..I want it to be converted to 235

and ..

we cant convert to integer .then also we will be getting zero's,that would not work.

0 Kudos

I write an example

xsl file:

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

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

<xsl:template match="/">

<doc>

<xsl:apply-templates/>

</doc>

</xsl:template>

<xsl:template match="source_field">

<source_field>

<xsl:call-template name="remove_leading_zeros">

<xsl:with-param name="value" select="."/>

</xsl:call-template>

</source_field>

</xsl:template>

<xsl:template name="remove_leading_zeros">

<xsl:param name="value"/>

<xsl:choose>

<xsl:when test="starts-with($value, '0')">

<xsl:call-template name="remove_leading_zeros">

<xsl:with-param name="value" select="substring($value, 2)"/>

</xsl:call-template>

</xsl:when>

<xsl:otherwise>

<xsl:value-of select="$value"/>

</xsl:otherwise>

</xsl:choose>

</xsl:template>

</xsl:stylesheet>

to test:

input xml:

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

<doc>

<source_field>000000123456</source_field>

<source_field>0987654</source_field>

</doc>

output xml:

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

<doc xmlns:fo="http://www.w3.org/1999/XSL/Format">

<source_field>123456</source_field>

<source_field>987654</source_field>

</doc>

hope can help you.

regards

Bin

Former Member
0 Kudos

Hi,

Try this xsl command...

<xsl:value-of select="replace(., '^0*', '')"/>

or check out this example..

<xsl:variable name="a">

<xsl:call-template name="removeLeadingZeros">

<xsl:with-param name="phone">

<xsl:value-of select="EVENT/ContactPhone"/>

</xsl:with-param>

</xsl:call-template>

</xsl:variable>

<xsl:template name="removeLeadingZeros">

<xsl:param name="phone"/>

<xsl:message>

<xsl:value-of select="$phone"/>

</xsl:message>

<xsl:choose>

<xsl:when test="starts-with($phone,'0')">

<xsl:call-template name="removeLeadingZeros">

<xsl:with-param name="phone">

<xsl:value-of

select="substring-after($phone,'0' )"/>

</xsl:with-param>

</xsl:call-template>

</xsl:when>

<xsl:otherwise>

<xsl:value-of select="$phone"/>

</xsl:otherwise>

</xsl:choose>

</xsl:template>

Hope this will help.

Nilesh

Answers (6)

Answers (6)

Former Member
0 Kudos

Hi ,

I am new to the xsl mapping...and this issue is of little priority to me...

so could you please check this code.

?xml version="1.0"?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns="urn:xi:liberty:fi:interface">

<xsl:output method="xml" indent="yes" encoding="UTF-8" />

<xsl:strip-space elements="*" />

<xsl:template match="Compass">

<ns:FIDOC_XI xmlns:ns="urn:xi:liberty:fi:interface">

<PROCESSID>

<xsl:value-of select="concat('CM',./Row[Field8='G']/Field1,./Row[Field8='G']/Field11)" />

</PROCESSID>

<SENDER_SERVICE>IP_COMPASS</SENDER_SERVICE>

<USER_EXIT>ZIP_COMPASS</USER_EXIT>

<IFLOG>X</IFLOG>

<SIMULATE>

</SIMULATE>

<xsl:call-template name="entity">

</xsl:call-template>

</ns:FIDOC_XI>

</xsl:template>

(Just I am copying the part where my required thing is there )

If you see the above mapping there is a field process id ..in this I am concatenating Field11 with the other things into processid...

Before I concatenate this field11 with all the other fields into Processid ..I need to remove all the leading zero's from field11..

So can any one help me out on how I create code to remove the zero's ...

Thanks in advance,

Vengal.

Former Member
0 Kudos

My code is like this

<xsl:template match="Count">

<ns:FIDOC_XI xmlns:ns="urn:xi:liberty:fi:interface">

<PROCESSID>

<xsl:value-of select=

"concat('CM',,replace(./RowField8='G']/Field11, '^0*', ''))" />

</PROCESSID>

</ns:FIDOC_XI>

</xsl:template>

In this I need to write apply conditions on Process Id i.e Field11...(I am placing only this part of xsl code)

Former Member
0 Kudos

Target type is char 20

source is xsd;string

Former Member
0 Kudos

I am using XSL mapping and there are many other fields to map,

so how do I trigger this particular UDF to map only this field...it is not a message mapping...

Former Member
0 Kudos

I guess if you convert it into integer then automatically all leading zeros will be removed. And then again convert it into string.

Message was edited by:

Sarvesh Singh

0 Kudos

Does the target field have a certein format or only a normal string.

Former Member
0 Kudos

Regards,

Sarvesh

Message was edited by:

Sarvesh Singh

0 Kudos

Try the "user function definition".