cancel
Showing results for 
Search instead for 
Did you mean: 

Truncating the leading zeros

Former Member
0 Kudos

hi,

Could anybody pls tell me how do i truncate the leading zeros in the incoming file structure.

Thanks,

Chinna

Accepted Solutions (1)

Accepted Solutions (1)

former_member181962
Active Contributor
0 Kudos

YOu can write java code to do this in a UDF.

refer this link:

http://www.stylusstudio.com/xsllist/200301/post01150.html

Regards,

Ravi

Answers (7)

Answers (7)

Former Member
0 Kudos

Thanks for your replies..

Regds,

Chinna

aashish_sinha
Active Contributor
0 Kudos

Hi,

Check this thread, i laready answered it there.

For you i pasting the solution here.

Write a UDF like this ..

public class test {

public static void main(String[] args) {

System.out.println(args[0].replaceAll("^0*",""));

}

}

Also you can use XSLT for this.

Try the XPath function number($string) in your XSLT and see if it does what you want. Since it turns any XPath object into a number, the leading zeros won't appear.

Use it ike this

<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>

Regards

Aashish Sinha

PS : Reward Point if Helpful

Former Member
0 Kudos

Hello everyone,

Thanks for the replies. I have a problem. I have written a USD for truncating the zeros. when i was trying to test it by giving some constant values, using the display queue option i see a processing log window pops up and the hangs up for some time without giving the output results. I tried it number of times but the same thing pops up.

You help would be appreciated.

Thanks,

Chinna

agasthuri_doss
Active Contributor
0 Kudos

Hi,

Use - round or Abs function that will hep you.

Give the leading zeroes to the source field and Try testing in the Test tab option.

Regards

Agasthuri Doss

Former Member
0 Kudos

Hi

Instead of UDF you can use Format Number (standard Function).

Thanks

Former Member
0 Kudos

While mapping you can create an udf which will suppess the zeroes while getting mapped with the target field..

thanx pankaj

Former Member
0 Kudos

Hi Reddy,

There are functions available in message mapping like ceil ,floor , round andformatnumbe...

These functions are capable of fulfilling your requirement .

Regards,

Former Member
0 Kudos

HI Chinna,

use FormatNumber function and give just ####### and you get the result with out zeros.

I also had the similar requirement and i just used this function instead of UDF

Thanks,

Raj

Former Member
0 Kudos

use <b>ceil or floor or round</b> depending on your requirement.