XML Editor
Sign up for a WebBoard account Sign Up Keyword Search Search More Options... Options
Chat Rooms Chat Help Help News News Log in to WebBoard Log in Not Logged in
Show tree view Topic
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Postnext
Archie CampbellSubject: Howto replace a comma with a blank
Author: Archie Campbell
Date: 07 Dec 2006 06:33 PM
I have build a .xsl file to transform an .xml file to another .xml file.
It works nicely.
Now I want to remove any comma in a field with a null
eg
120,352 becomes 120352
I also want to remove any # character with a blank
eg
Suite#3210 becomes Suite 3210

Its seems like a simple thing to do (and probably is) but I cannot figure out how to do it.

Thanks
Archie Campbell

Postnext
Barry DeBruinSubject: Howto replace a comma with a blank
Author: Barry DeBruin
Date: 07 Dec 2006 06:58 PM
I can't remember who to give credit to, but paste this template after the <xsl:output> tag:
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:choose>
<xsl:when test="contains($text, $from)">
<xsl:variable name="before" select="substring-before($text, $from)"/>
<xsl:variable name="after" select="substring-after($text, $from)"/>
<xsl:variable name="prefix" select="concat($before, $to)"/>
<xsl:value-of select="$before"/>
<xsl:value-of select="$to"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="$after"/>
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$to"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


And then call where needed:

<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="pasteXPathHere"/>
<xsl:with-param name="from" select="','"/>
<xsl:with-param name="to" select="' '"/>
</xsl:call-template>

Postnext
Archie CampbellSubject: Howto replace a comma with a blank
Author: Archie Campbell
Date: 07 Dec 2006 08:24 PM
More complicated than I thought but all the better for learning.

Thanks Brian.

Postnext
Barry DeBruinSubject: Howto replace a comma with a blank
Author: Barry DeBruin
Date: 07 Dec 2006 09:24 PM
No problem.. I thought it was a little overly complicated as well, but it works.

Barry

Postnext
Archie CampbellSubject: Howto replace a comma with a blank
Author: Archie Campbell
Date: 07 Dec 2006 10:05 PM
More complicated than I thought but all the better for learning.

Thanks Brian.

Postnext
Tony LavinioSubject: Howto replace a comma with a blank
Author: Tony Lavinio
Date: 08 Dec 2006 12:46 AM
For single-character replacements or removals, just use
the translate function.

Translate(expression, ',', '') will remove commas from the
expression.

Translate(expression, '#', ' ') will replace the # with a
space.

In XSLT 2.0 there is a full string search-and-replace
function. But in 1.0, for single-character replacements,
there is no need to dive deep into recursion.

See http://www.w3.org/TR/xpath#function-translate for
more details.

Postnext
Archie CampbellSubject: Howto replace a comma with a blank
Author: Archie Campbell
Date: 08 Dec 2006 01:36 AM
Thanks for that Toni.
I have noted function-translate and search-and-replace for next time.
Obviously much simpler.

Brian's stuff is working fine so I am going to keep it.
Plus I haven't done recursion code for a while and it was fun just doing it as yet another learning lesson with xslt.
;-)

Thanks to both Brian and Toni.

Archie

Postnext
Maurice GonsalvesSubject: Howto replace a comma with a blank
Author: Maurice Gonsalves
Date: 29 May 2008 08:21 AM
Hello Tony! I saw the Translate syntax you had provided for someone. I have similar issues....I'm new in XSLT. If you can provide some direction, that would be great!

I have the the mapping below for which I need to replace all the commas for certain fields (e.g. E1KNA1M/NAME1 & E1KNA1M/NAME2).

I know that the syntaxes are these....

"<xsl:value-of select='translate(E1KNA1M/NAME1,',',' ')"/>
&
"<xsl:value-of select='translate(E1KNA1M/NAME2,',',' ')"/>

But my problem is where do I put them (the structure/location of the coding)??




<xsl:for-each select="ns:Messages/child::*">
<xsl:for-each select="IDOC/E1KNA1M/Z1Z1SD_US_E1KNA1M_EXT">

<xsl:variable name="vtweg">
<xsl:value-of select="concat(VTWEG, VKORG, KVGR3)"/>
</xsl:variable>

<Record>
<xsl:for-each select="parent::E1KNA1M">
<CUSTOMER>
<xsl:value-of select="KUNNR"/>
</CUSTOMER>
</xsl:for-each>
<DIST_CHANNEL>
<xsl:value-of select="VTWEG"/>
</DIST_CHANNEL>
<xsl:for-each select="parent::E1KNA1M">
<NAME1>
<xsl:value-of select="NAME1"/>
</NAME1>
<NAME2>
<xsl:value-of select="NAME2"/>
</NAME2>
<ADDRESS1>
<xsl:value-of select="STRAS"/>
</ADDRESS1>
</xsl:for-each>

<ADDRESS2>
<xsl:value-of select="ADDRESS"/>
</ADDRESS2>

<xsl:for-each select="parent::E1KNA1M">
<CITY>
<xsl:value-of select="ORT01"/>
</CITY>
<STATE>
<xsl:value-of select="REGIO"/>
</STATE>
<ZIPCODE>
<xsl:value-of select="PSTLZ"/>
</ZIPCODE>
<COUNTRY>
<xsl:value-of select="LAND1"/>
</COUNTRY>

</xsl:for-each>

<CUS_HIERARCHY_1>
<xsl:value-of select="HIER1"/>
</CUS_HIERARCHY_1>
<CUS_HIERARCHY_2>
<xsl:value-of select="HIER2"/>
</CUS_HIERARCHY_2>

Posttop
(Deleted User) Subject: Howto replace a comma with a blank
Author: (Deleted User)
Date: 29 May 2008 12:43 PM
Please post your message in one thread only.

Thanks,
Alberto

 
Topic Page 1 2 3 4 5 6 7 8 9 Go to previous topicPrev TopicGo to next topicNext Topic
Download A Free Trial of Stylus Studio 6 XML Professional Edition Today! Powered by Stylus Studio, the world's leading XML IDE for XML, XSLT, XQuery, XML Schema, DTD, XPath, WSDL, XHTML, SQL/XML, and XML Mapping!  
go

Log In Options

Site Map | Privacy Policy | Terms of Use | Trademarks
Stylus Scoop XML Newsletter:
W3C Member
Stylus Studio® and DataDirect XQuery ™are from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2016 All Rights Reserved.