This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: New line characters to </br> element.
- To: "Jakub Maly" <jakub_maly at yahoo dot com>
- Subject: Re: [xsl] New line characters to </br> element.
- From: Jeni Tennison <mail at jenitennison dot com>
- Date: Sun, 4 Mar 2001 18:28:59 +0000
- CC: "xsl-list" <xsl-list at lists dot mulberrytech dot com>
- Organization: Jeni Tennison Consulting Ltd
- References: <008901c0a4cb$e37536c0$8cb30ac3@telia.fi>
- Reply-To: xsl-list at lists dot mulberrytech dot com
Hi Jakub,
> I have problem with displaying of text, which contain new line
> characters, when I transcode XSL to HTML. I guess that it is more
> problem of HTM than of XSL. So, HTML cuts these characters and
> represent theme as a space. But, I think, that there could by some
> way how to translate newline characters to for example </br>
> element. Is there any way? Or, does anybody know any other solution?
You could try using the CSS 'white-space' property set to 'pre', e.g.:
<p style="white-space: pre;">
...
</p>
but you might not get much joy because browsers can legally ignore the
property.
The other option is to replace all the line breaks (i.e. 

characters) in the text with 'br' elements) using a recursive named
template like:
<xsl:template name="add-line-breaks">
<xsl:param name="string" select="." />
<xsl:choose>
<xsl:when test="contains($string, '
')">
<xsl:value-of select="substring-before($string, '
')" />
<br />
<xsl:call-template name="add-line-breaks">
<xsl:with-param name="string"
select="substring-after($string, '
')" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$string" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
You can call this template as appropriate with the $string parameter
being passed the value of the string that you want to perform the
replacement on.
I hope that helps,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list