RE: [xsl] Hmmmm.... translate function

Subject: RE: [xsl] Hmmmm.... translate function
From: "XSLList" <xsllist@xxxxxxxxxxxxx>
Date: Sat, 15 Mar 2003 16:05:44 -0500
> that won't work with his example
>If @div = "12 All +" you'll get:
>12 All %12 All 212 All B
>And what he wants is:
>12 All %2B

You're right Americo.  This will work (I'm sure someone's already done one
of these somewhere on the FAQ.  Just a good exercise) using his + to %2B
requirements....

Jeff

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="text"/>

<xsl:template match="/">
	<!-- test replaceString template -->
		<xsl:call-template name="replaceString">
			<xsl:with-param name="original"
select="'One+Flew+Over+The+Cuckoos+Nest'"/>
			<xsl:with-param name="find" select="'+'"/>
			<xsl:with-param name="replace" select="'%2B'"/>
		</xsl:call-template>
</xsl:template>

<xsl:template name="replaceString">
	<xsl:param name="original" select="string('')"/>
	<xsl:param name="find" select="string('')"/>
	<xsl:param name="replace" select="string('')"/>

	<xsl:choose>
		<xsl:when test="contains($original, $find)">
			<xsl:call-template name="replaceString">
				<xsl:with-param name="original"
select="concat(substring-before($original, $find),$replace,
substring-after($original, $find))"/>
				<xsl:with-param name="find" select="$find"/>
				<xsl:with-param name="replace" select="$replace"/>
			</xsl:call-template>
		</xsl:when>
		<xsl:otherwise>
			<xsl:value-of select="$original"/>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>

</xsl:stylesheet>


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


Current Thread