Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > BOOK: XSLT Programmer's Reference, 2nd Edition
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
BOOK: XSLT Programmer's Reference, 2nd Edition
This is the forum to discuss the Wrox book XSLT: Programmer's Reference, 2nd Edition by Michael Kay; ISBN: 9780764543814
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: XSLT Programmer's Reference, 2nd Edition section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old May 20th, 2008, 04:38 PM
Registered User
Join Date: May 2008
Location: , , .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Replacing multiple characters in a string


Goal: Replace multiple characters in a text string. I want to replace all occurences.
Parser: Altova built-in parser
OS: Windows XP
Issue: First character in the search replaces all occurences
  Second character replaces last character, not first occurence
Third character does not get replaced

Source XML
<content>Register symbol® Copyright symbol© registration symbol again® trademark symbol™ copyright symbol again©</content>

Output XML (ignore "_" underscore in numeric character entities)
 <content>Register symbol&_#174; Copyright symbol© registration symbol again#_174; trademark symbol™ copyright symbol#_169; again</content>

<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:param name="reg.search" select="'®'"/>
<xsl:param name="reg.replace">
<xsl:param name="copy.search" select="'©'"/>
<xsl:param name="copy.replace">
<xsl:param name="trade.search" select="'™'"/>
<xsl:param name="trade.replace">
<xsl:template name="search-replace">
<xsl:param name="text"/>
<xsl:when test="contains($text, $reg.search)">
<xsl:value-of select="substring-before($text, $reg.search)"/>
<xsl:value-of select="$reg.replace" disable-output-escaping="yes"/>
<xsl:call-template name="search-replace">
<xsl:with-param name="text" select="substring-after($text, $reg.search)"/>
<xsl:when test="contains($text, $copy.search)">
<xsl:value-of select="substring-before($text, $copy.search)"/>
<xsl:value-of select="$copy.replace" disable-output-escaping="yes"/>
<xsl:call-template name="search-replace">
<xsl:with-param name="text" select="substring-after($text, $copy.search)"/>
<xsl:when test="contains($text, $trade.search)">
<xsl:value-of select="substring-before($text, $trade.search)"/>
<xsl:value-of select="$trade.replace" disable-output-escaping="yes"/>
<xsl:call-template name="search-replace">
<xsl:with-param name="text" select="substring-after($text, $trade.search)"/>
<xsl:value-of select="$text"/>
<xsl:template match="*">
<xsl:copy-of select="@*"/>
<xsl:template match="text()">
<xsl:call-template name="search-replace">
<xsl:with-param name="text" select="."/>

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Separating strings and replacing characters sunrain XSLT 4 April 7th, 2008 09:33 AM
replacing numbers in a string cole SQL Server 2000 4 April 2nd, 2007 04:24 PM
Replacing characters in a string semilemon C# 2005 2 June 16th, 2006 11:31 PM
Replacing characters in external csv file Axxess Access VBA 2 July 15th, 2005 01:39 AM
Replacing a character from string itHighway Classic ASP Basics 5 March 14th, 2005 11:15 PM

All times are GMT -4. The time now is 08:29 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.