[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: xslt replace special characters

Subject: Re: xslt replace special characters
From: "Alice Fan" <arisuu@xxxxxxxxxxx>
Date: Fri, 08 Nov 2002 12:14:37 -0800
xslt replace
Hi..

thank you. it works if i just use it for one character. can i put in more than one character in the pattern variable at once? if i keep calling the template, obviously i will get the string variable the number of i call the template. so what do you suggest that i do if i have a string like this. http://www.domain.com?xxx=yyy&www=y

thanks
al


From: Greg Faron <gfaron@xxxxxxxxxxxxxxxxxx>
Reply-To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re:  xslt replace special characters
Date: Fri, 08 Nov 2002 12:51:21 -0700

At 12:40 PM 11/8/2002, you wrote:
How do you replace characters in xslt.

i have a url string that may contain '?' , '&', and '='
i want to convert

? to %3f
= to %3d
& to %26

is there a good way to do this? i try using translate function but it doesn't work that well. i've also tried writing a recursive template that checks for all occurence of these characters and it doesnt seem to work.
any idea?

<xsl:template name="replace">
<xsl:param name="string" select="''"/>
<xsl:param name="pattern" select="''"/>
<xsl:param name="replacement" select="''"/>
<xsl:choose>
<xsl:when test="$pattern != '' and $string != '' and contains($string, $pattern)">
<xsl:value-of select="substring-before($string, $pattern)"/>
<!--
Use "xsl:copy-of" instead of "xsl:value-of" so that users
may substitute nodes as well as strings for $replacement.
-->
<xsl:copy-of select="$replacement"/>
<xsl:call-template name="replace">
<xsl:with-param name="string" select="substring-after($string, $pattern)"/>
<xsl:with-param name="pattern" select="$pattern"/>
<xsl:with-param name="replacement" select="$replacement"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>



Greg Faron Integre Technical Publishing Co.



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list


..........................................................
Email: arisuu@xxxxxxxxxxx
Cell: (650) 483-8164
Work: (212) 201-0881
..........................................................nk

_________________________________________________________________
Add photos to your messages with MSN 8. Get 2 months FREE*. http://join.msn.com/?page=features/featuredemail



XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.