I use a template to replace special characters in a text file:
from to <br/>,
from " " to ( ),
from (	) to (   ),
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 " " 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 " " ), 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="' '"/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="pattern" select="'	'"/>
<xsl:with-param name="replacement"
select="'   '"/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="pattern" select="' '"/>
<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="' '"/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="pattern" select="'	'"/>
<xsl:with-param name="replacement"
select="'   '"/>
</xsl:call-template>
</xsl:with-param>
<xsl:with-param name="pattern" select="' '"/>
<xsl:with-param name="replacement" select="''"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>