[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Replace Special Characters: return, blank and tab

Subject: Replace Special Characters: return, blank and tab
From: "Christina" <lechaelnah@xxxxxxxxxxx>
Date: Thu, 5 Aug 2004 16:30:58 -0700
xsl replace
I use a template to replace special characters in a text file:
from &#13; to <br/>,
from  " " to (&#160;),
from  (&#9;) to   (&#160;&#160;&#160;),
it turns out the blank and tab works well, but the <br/> isn't inserted,
what is funny is that I tried to replace the "&#13;" with <p>hereIAm</p>,
the text "hereIAm" is inserted, but its wrapping <p> is stripped.
If I only call the template once (only to replace the "&#13;" ), then it
works fine<p>hereIAm</p> is inserted as a whole ,
 I don't know what is the problem,
would anybody throw me a light on it?
Thanks!

here is my code:
 <xsl:template match="/">
    <content>
     <xsl:call-template name="replace">
         <xsl:with-param name="string">
              <xsl:call-template name="replace">
                 <xsl:with-param name="string">
                      <xsl:call-template name="replace">
                          <xsl:with-param name="string" select="."/>
                          <xsl:with-param name="pattern" select="' '"/>
                          <xsl:with-param name="replacement"
select="'&#160;'"/>
                      </xsl:call-template>
                 </xsl:with-param>
                 <xsl:with-param name="pattern" select="'&#9;'"/>
                 <xsl:with-param name="replacement"
select="'&#160;&#160;&#160;'"/>
              </xsl:call-template>
              </xsl:with-param>
              <xsl:with-param name="pattern" select="'&#13;'"/>
              <xsl:with-param name="replacement" select="'"/>
      </xsl:call-template>
    </content>
  </xsl:template>
  <xsl:template name="replace">
     <xsl:param name="string" />
     <xsl:param name="pattern" />
     <xsl:param name="replacement" />
     <xsl:choose>
          <xsl:when test="$pattern != '' and $string != '' and
contains($string, $pattern)">
              <xsl:value-of select="substring-before($string, $pattern)" />
              <xsl:choose>
                 <xsl:when test="$replacement != ''">
                 <xsl:copy-of select="$replacement" />
             </xsl:when>
             <xsl:otherwise>
                 <p>hereIam</p>
             </xsl:otherwise>
        </xsl:choose>

        <xsl:call-template name="replace">
            <xsl:with-param name="string">
              <xsl:call-template name="replace">
                 <xsl:with-param name="string">
                      <xsl:call-template name="replace">
                          <xsl:with-param name="string"
select="substring-after($string, $pattern)"/>
                          <xsl:with-param name="pattern" select="' '"/>
                          <xsl:with-param name="replacement"
select="'&#160;'"/>
                      </xsl:call-template>
                 </xsl:with-param>
                 <xsl:with-param name="pattern" select="'&#9;'"/>
                 <xsl:with-param name="replacement"
select="'&#160;&#160;&#160;'"/>
              </xsl:call-template>
              </xsl:with-param>
              <xsl:with-param name="pattern" select="'&#13;'"/>
              <xsl:with-param name="replacement" select="''"/>
        </xsl:call-template>

      </xsl:when>
      <xsl:otherwise>
            <xsl:value-of select="$string" />
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

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.