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

Re: Convert newlines to <BR/>

Subject: Re: Convert newlines to <BR/>
From: "Richman, Jeremy" <jrichman@xxxxxxxxxxxx>
Date: Thu, 30 Dec 1999 18:18:50 -0500
xsl convert newline to br
You can simply this further by using a match pattern predicate.

<xsl:template match="programlisting/text()[contains['&#xA']">
...
</xsl:template>

Jeremy Richman



Date: Tue, 28 Dec 1999 23:27:17 -0800
From: "Steve Muench" <smuench@xxxxxxxxxxxxx>
Subject: Re: Convert newlines to <BR/>

This solution works for me:

Given the input document:

<doc>
  <p>This is some text.</p>
  <programlisting><![CDATA[This is a paragraph
  with some newlines
  does it work?]]></programlisting>
</doc>

The stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<html>
  <head/>
  <body>
  <xsl:apply-templates/>
  </body>
</html>
</xsl:template>

<xsl:template match="p">
<p><xsl:apply-templates/></p>
</xsl:template>

<xsl:template match="programlisting">
  <span style="font-family:monospace">
  <xsl:call-template name="br-replace">
    <xsl:with-param name="word" select="."/>
  </xsl:call-template>
  </span>
</xsl:template>

<xsl:template name="br-replace">
  <xsl:param name="word"/>
   <!-- </xsl:text> on next line on purpose to get newline -->
  <xsl:variable name="cr"><xsl:text>
</xsl:text></xsl:variable>
  <xsl:choose>
  <xsl:when test="contains($word,$cr)">
      <xsl:value-of select="substring-before($word,$cr)"/>
      <br/>
      <xsl:call-template name="br-replace">
        <xsl:with-param name="word" select="substring-after($word,$cr)"/>
      </xsl:call-template>
  </xsl:when>
  <xsl:otherwise>
    <xsl:value-of select="$word"/>
  </xsl:otherwise>
 </xsl:choose>
</xsl:template>

</xsl:stylesheet>


Produces:

<html>
<head>
</head>
<body>
  <p>This is some text.</p>
  <span style="font-family:monospace">This is a paragraph<br>  with some
newlines<br>  does it work?</span>
</body>
</html>

Which seems to be like what you want...

_________________________________________________________
Steve Muench, Consulting Product Manager & XML Evangelist
Business Components for Java Development Team
http://technet.oracle.com/tech/java
http://technet.oracle.com/tech/xml
- ----- Original Message -----
From: "Jon Smirl" <jonsmirl@xxxxxxxxxxxx>
To: "XSLList" <xsl-list@xxxxxxxxxxxxxxxx>
Sent: Tuesday, December 28, 1999 10:10 PM
Subject: Convert newlines to <BR/>


| I have text that contains newlines and I want to replace these with <BR/>.
I
| can't use <PRE> for the output because I need word-wrap to work. Any ideas
| on how to do the conversion? translate(a, b, c) only does single character
| replacements.
|
| Using XT.
|
| Jon Smirl
| jonsmirl@xxxxxxxxxxxx
|
|
|
|  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
|


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

------------------------------

End of The XSL-List Digest V2 #451
**********************************



 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.