[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Replace Special Characters: return, blank and tab
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>
|
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
|