Hi,
Do we have any way to replace ALL different characters in String with other
characters in ONE SINGLE shot?
Example: I have a String "® ™" and the resulting String should be
"® ™". Which means '®' should be replaced by
'®', '™' should be replaced by '™'.
Below is what I am doing right now. It is working, but I am happening to
call the template once for each string replacement. Thus, it becomes slow. I
want to know if there is any way we can replace ALL the strings in a SINGLE
call:
<description>
<xsl:text
disable-output-escaping="yes"><![CDATA[<![CDATA[]]></xsl:text>
<xsl:variable name="repregdesc">
<xsl:call-template name="do-replace">
<xsl:with-param name="text">
<xsl:copy-of
select="normalize-space(translate(DESCRIPTION,'ý',' '))"/>
</xsl:with-param>
<xsl:with-param name="replace">®</xsl:with-param>
<xsl:with-param name="by">
<xsl:text
disable-output-escaping="yes">&#174;</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:call-template name="do-replace">
<xsl:with-param name="text">
<xsl:copy-of select="$repregdesc"/>
</xsl:with-param>
<xsl:with-param name="replace">
™
</xsl:with-param>
<xsl:with-param name="by">
<xsl:text
disable-output-escaping="yes">&#8482;</xsl:text>
</xsl:with-param>
</xsl:call-template>
<xsl:text
disable-output-escaping="yes"><![CDATA[]]]]>></xsl:text>
</description>
and the do-replace template is as follows:
<xsl:template name="do-replace">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:copy-of select="substring-before($text,$replace)"/><xsl:copy-of
select="$by"/><xsl:call-template name="do-replace">
<xsl:with-param name="text"><xsl:copy-of
select="substring-after($text,$replace)"/></xsl:with-param>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="by"><xsl:copy-of
select="$by"/></xsl:with-param>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Any help would be greatly appreciated.
Thanks,
Pramodh.
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list