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
Conferences Close Tree View
+ Stylus Studio Feature Requests (1192)
+ Stylus Studio Technical Forum (14621)
+ Website Feedback (249)
- XSLT Help and Discussion (7625)
-> + Use of before and after string (3) Sticky Topic
-> - How do I substitute element ty... (1)
-> + How does one add working days ... (4)
-> - Help, I have existing XLT and... (1)
-> + Need help on XSLT issue - (2)
-> + EDI to XML Conversion (7)
-> - XML To JSON Conversion using X... (1)
-> + Formatting Paragraphs to same ... (2)
-> - Grouping of records (1)
-> + Problems with xsd 1.1 (4)
-> + XML to HL7 mapping (3)
-> + XSLT 3 and Iterate (2)
-> + XSL-FO to PDF preview (3)
-> + java.lang.RuntimeException: Er... (2)
-> + Create Acroforms with Stylus X... (2)
-> + How to change XSLT parameter s... (3)
-> + how to change format of the da... (2)
-> + Search "Next 8 Results " doesn... (2)
-> - Support for Git (1)
-> + newbee (8)
-- [1-20] [21-40] [41-60] Next
+ XQuery Help and Discussion (2017)
+ Stylus Studio FAQs (159)
+ Stylus Studio Code Samples & Utilities (364)
+ Stylus Studio Announcements (113)
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

   
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.