This post contains attachments v20010223112713.zip 
Summary
This example demonstrates how to replace carriage returns with a break in XSLT. It is also a generic template for handling any search and replace.
This example explains how to replace a carriage return with a break (<br />) in XSLT, so that the carriage return is preserved in a paragraph (<p>) in the HTML output.
In my XML example I have the following text in a CDATA section:
<blurb> <info> <![CDATA[This displays many rows that we want to output.
The carriage return needs to be replaced in this example.]]> </info> </blurb>
If I want to output this information in a <p> element (as I don't want to use a <pre>), the output of my example will be:
This displays many rows that we want to output. The carriage return needs to be replaced in this example.
All my carriage returns are lost!
When I first tackled this problem I was looking at the XPath translate() function solution. But because the special character for a carriage return is , I actually need to do a replace of a word and not just a character.
So this example shows how you can replace the with a <br />. This is an example of recursions where the template 'normalize-text' is called over and over inside of itself as it iterates through each word in the para. If a carriage return is found, does the <br /> replace.
To achieve this replace I've used:
<xsl:value-of select=substring-before($text, $replace)/> <xsl:value-of select=$by disable-output-escaping=yes/>
The attribute 'disable-output-escaping' tells the XSL processor to not escape any special characters, but to output exactly what is in the text node.
|