[xsl] multiple search and replace

Subject: [xsl] multiple search and replace
From: "Norma Yeazell" <Nyeazell@xxxxxxxxx>
Date: Fri, 30 Apr 2004 10:37:56 -0400
The following snip works fine but can anyone tell me whether there is a
better more efficient way to replace more than one item.

<xsl:template match="text()">
  <xsl:call-template name="_replace_string">
    <xsl:with-param name="string" select="." />
    <xsl:with-param name="find" select="'?degrees?'" />
    <xsl:with-param name="replace" select="'&#xB0;'" />
    <xsl:with-param name="find2" select="'Nm'" />
    <xsl:with-param name="replace2" select="'N&#xb7;m'" />
  </xsl:call-template>
</xsl:template>

<!-- template to look for all instances of string $find and
replace that with string $replace -->
<xsl:template name="_replace_string">
<xsl:param name="string" select="''"/>
<xsl:param name="find" select="'find'"/>
<xsl:param name="replace" select="'replace'"/>
<xsl:param name="find2" select="'find2'"/>
<xsl:param name="replace2" select="'replace2'"/>
<xsl:choose>
<xsl:when test="contains($string,$find)">
<xsl:value-of
select="concat(substring-before($string,$find),$replace)"/>
<xsl:call-template name="_replace_string">
<xsl:with-param name="string" select="substring-after($string,$find)"/>
<xsl:with-param name="find" select="$find"/>
<xsl:with-param name="replace" select="$replace"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="contains($string,$find2)">
<xsl:value-of
select="concat(substring-before($string,$find2),$replace2)"/>
<xsl:call-template name="_replace_string">
<xsl:with-param name="string" select="substring-after($string,$find2)"/>
<xsl:with-param name="find2" select="$find2"/>
<xsl:with-param name="replace2" select="$replace2"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>



Confidentiality Notice
The information contained in this e-mail is confidential and intended for use only by the person(s) or organization listed in the address. If you have received this communication in error, please contact the sender at O'Neil & Associates, Inc., immediately. Any copying, dissemination, or distribution of this communication, other than by the intended recipient, is strictly prohibited.

Current Thread