[xsl] Replace Special Characters: return, blank and tab

Subject: [xsl] Replace Special Characters: return, blank and tab
From: "Christina" <lechaelnah@xxxxxxxxxxx>
Date: Thu, 5 Aug 2004 16:30:58 -0700
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