[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] replacing ALL chars in a string in a SINGLE shot
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 "&#174; &#8482;". Which means '®' should be replaced by '&#174;', '™' should be replaced by '&#8482;'. 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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|