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

Re: Formatting white space with xslt

Subject: Re: Formatting white space with xslt
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 21 Nov 2003 10:24:33 +0000
white space in xsl
Hi Olmec,

> Imagine the following XML
>
> <root>
>         <item itemId="0" value="line1
>         line2
>         line2"/>
> </root>
>
> The content in the value attribute is saved from a textarea field in
> an HTML form and is returned in XML as shown above.
>
> When I try and access the data in the value attribute with value-of
> select all white space is stripped and all lines are shown on a
> single line.

I'm afraid that's beyond the control of the XSLT processor. The XML
Recommendation states that when the value of an attribute is reported
to an application, it must be normalized [1]. Attribute value
normalization, at its minimum level, replaces any newlines with
spaces; if you declare the attribute in a DTD as anything aside from
CDATA, then it performs even more whitespace normalization, equivalent
to calling normalize-space() on the value in XSLT terms.

So as far as the XSLT processor is concerned, it's exactly as if the
value attribute never contained any newlines in the first place.

If newlines are important, I suggest you either use the content of the
<item> element (rather than its value attribute) to hold the result of
the textarea from the HTML form, or that you ensure that the newline
characters are escaped using character references (i.e. "&#xA;")
within the value attribute. That way, the whitespace will be
preserved.

Cheers,

Jeni

[1] http://www.w3.org/TR/REC-xml#AVNormalize

---
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.