This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: Documentation on string-replace
- To: xsl-list at mulberrytech dot com
- Subject: Re: Documentation on string-replace
- From: David Carlisle <davidc at nag dot co dot uk>
- Date: Thu, 17 Feb 2000 23:39:15 GMT
- References: <38AC833B.B350FEF@promedix.com>
- Reply-To: xsl-list at mulberrytech dot com
> I have seen some references to a string-replace function in XSL and
'tis a little routine of mine.
<!-- replace all occurences of the character(s) `from'
by the string `to' in the string `string'.-->
<xsl:template name="string-replace" >
<xsl:param name="string"/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:choose>
<xsl:when test="contains($string,$from)">
<xsl:value-of select="substring-before($string,$from)"/>
<xsl:value-of select="$to"/>
<xsl:call-template name="string-replace">
<xsl:with-param name="string" select="substring-after($string,$from)"/>
<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="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
there are some examples of its use in the faq I think.
David
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list