[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

Subject: replacing ALL chars in a string in a SINGLE shot
From: "Pramodh Peddi" <peddip@xxxxxxxxxxxxxxxx>
Date: Wed, 14 Jan 2004 11:37:40 -0500
amp 174
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 "&#174; &#8482;" and the resulting String should be
"&amp;#174; &amp;#8482;". Which means '&#174;' should be replaced by
'&amp;#174;', '&#8482;' should be replaced by '&amp;#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">&#174;</xsl:with-param>
              <xsl:with-param name="by">
                <xsl:text
disable-output-escaping="yes">&amp;#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">
                &#8482;
              </xsl:with-param>
              <xsl:with-param name="by">
                <xsl:text
disable-output-escaping="yes">&amp;#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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.