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

Re: Formatting CDATA information

Subject: Re: Formatting CDATA information
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Sat, 27 Jan 2001 12:00:43 +0000
xslt substitute string whitespace
Hi Tina,

> The problem is that when this gets converted to HTML all of the line
> breaks in the CDATA section are lost, and it becomes one long line.
> Is there a way to format what's inside the CDATA tag to have <br>
> after each line?

Sure.  The following template uses recursion to go through a string
and substitute all the line breaks (&#xA;) with 'br' elements.  (These
are the default substitutions - you can substitute other things by
passing different values for the $from and $to parameters.)

<xsl:template name="substitute">
   <xsl:param name="string" />
   <xsl:param name="from" select="'&#xA;'" />
   <xsl:param name="to">
      <br />
   </xsl:param>
   <xsl:choose>
      <xsl:when test="contains($string, $from)">
         <xsl:value-of select="substring-before($string, $from)" />
         <xsl:copy-of select="$to" />
         <xsl:call-template name="substitute">
            <xsl:with-param name="string"
                            select="substring-after($string, $from)" />
            <xsl:with-param name="from" select="$from" />
            <xsl:with-param name="to" select="$to" />
         </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
         <xsl:value-of select="$string" />
      </xsl:otherwise>
   </xsl:choose>
</xsl:template>                

So, for your example you can call the above template on the failure
information using:

<xsl:template match="failure">
      <p>FAILURE INFO:</p>
      <xsl:call-template name="substitute">
         <xsl:with-param name="string" select="." />
      </xsl:call-template>
</xsl:template>

The other option, of course, is to use the HTML 'pre' element or to
use the CSS white-space property set to 'pre' to tell the browser to
take notice of the whitespace in the HTML that you're producing.
These might be easier to handle than recursing through the string.

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.