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

Re: Word Wrap and PRE

Subject: Re: Word Wrap and PRE
From: "Steve Muench" <smuench@xxxxxxxxxxxxx>
Date: Tue, 26 Sep 2000 21:40:48 -0700
html pre word wrap
Here's an example from my soon-to-be-released book 
"Building Oracle XML Applications" where we work
through building an XSLT-powered online discussion forum
application. I use a combination of the following two 
templates to format code listings in the application.

You can use the routines by importing "UtilText.xsl" into
your stylesheet. Then, presuming your code example is selected by
the expression "programlisting", you could use this
with the code:

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

the inner call-template replaces occurrences of pairs of 
consecutive spaces with a pair of non-breaking spaces
represented by &#160;. The outer call-template replaces
line breaks with a <br/> tag.

<!-- UtilText.xsl: Common text formatting routines -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <!-- Replace new lines with html <br> tags -->
  <xsl:template name="br-replace">
    <xsl:param name="text"/>
    <xsl:variable name="cr" select="'&#xa;'"/>
    <xsl:choose>
      <!-- If the value of the $text parameter contains a carriage return... -->
      <xsl:when test="contains($text,$cr)">
        <!-- Return the substring of $text before the carriage return -->
        <xsl:value-of select="substring-before($text,$cr)"/>
        <!-- And construct a <br/> element -->
        <br/>
        <!--
         | Then invoke this same br-replace template again, passing the
         | substring *after* the carriage return as the new "$text" to
         | consider for replacement
         +-->
        <xsl:call-template name="br-replace">
          <xsl:with-param name="text" select="substring-after($text,$cr)"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
   </xsl:choose>
  </xsl:template>
  <!-- Replace two consecutive spaces w/ 2 non-breaking spaces -->
  <xsl:template name="sp-replace">
    <xsl:param name="text"/>
    <!-- NOTE: There are two spaces   ** here below -->
    <xsl:variable name="sp"><xsl:text>  </xsl:text></xsl:variable>
    <xsl:choose>
      <xsl:when test="contains($text,$sp)">
        <xsl:value-of select="substring-before($text,$sp)"/>
        <xsl:text>&#160;&#160;</xsl:text>
        <xsl:call-template name="sp-replace">
          <xsl:with-param name="text" select="substring-after($text,$sp)"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$text"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>
</xsl:stylesheet>

______________________________________________________________
Steve Muench, Lead XML Evangelist & Consulting Product Manager
BC4J & XSQL Servlet Development Teams, Oracle Rep to XSL WG
Author "Building Oracle XML Applications", O'Reilly
http://www.oreilly.com/catalog/orxmlapp/

----- Original Message ----- 
From: "Richard Saunders" <richards@xxxxxxxxxxxxxxxxx>
To: <XSL-List@xxxxxxxxxxxxxxxx>
Sent: Tuesday, September 26, 2000 5:56 PM
Subject: Word Wrap and PRE


| 
| I have a block of text from XML I wish to display on a web page. I wish to
| keep the same carriage returns and line spaces as the in the block of text
| in the XML. This I can do by using <PRE></PRE> in the XSL. However, the
| space I have on the HTML page is only 300 pix wide and <PRE> simply over
| runs this. How can I have the text maintain its format and word wrap at the
| same time?
| 
| Thanks
| 
| 
| Richard 
| 
| 
| 
|  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
| 


 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.