[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: New line characters to </br> element.

Subject: Re: New line characters to </br> element.
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sun, 4 Mar 2001 18:28:59 +0000
xsl translate newline
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. &#xA;
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, '&#xA;')">
         <xsl:value-of select="substring-before($string, '&#xA;')" />
         <br />
         <xsl:call-template name="add-line-breaks">
            <xsl:with-param name="string"
                            select="substring-after($string, '&#xA;')" />
         </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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.