on 10-19-2007 12:35 PM
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.
Do you want to remove all the leading zero's, or till 20-digital?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Target type is char 20
source is xsd;string
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Does the target field have a certein format or only a normal string.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Regards,
Sarvesh
Message was edited by:
Sarvesh Singh
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Try the "user function definition".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.