RE: Whitespace,xml:space,xsl:strip-space

Subject: RE: Whitespace,xml:space,xsl:strip-space
From: Kay Michael <Michael.Kay@xxxxxxx>
Date: Fri, 23 Jun 2000 17:42:24 +0100
> Am I correct in saying that :-
> 1. the default parser behaviour

Let's be clear here: we're talking about the XML parser, not the XSLT
processor, OK?

 (ie. when have not set the 
> parser NOT to include whitespace or overidden 
> ignorableWhitespace with a noop) is for all whitespace, ie. 
> leading and trailing whitespace, and also carriage returns 
> etc. to be passed to the application.

There are essentially three things an XML parser does with whitespace:
- it normalises line endings to a single #xa character
- it normalises whitespace in attribute values, depending on the attribute
- it distinguishes between whitespace in elements with element content and
whitespace in elements with pcdata or mixed content. However, an XSLT
processor ignores this distinction.

> The latter becoming whitespace-only text nodes.
This is now an XSLT (or XPath) concept rather than an XML concept. A
Whitespace-only text node arises (only) when all the text between two tags
is whitespace.
> 2. the effect of xml:space on whitespace-only text nodes 
> produced by the parser is that when xml:space ="preserve" 
> then the IsIgnorableWhitespace() method of these 
> whitespace-only text nodes will return false indicating that 
> they should not be discarded by the application; and when 
> xml:space="default" then the method will return false 
> indicating that can be discarded by the aqpplication.

Which spec are we talking about now? Whitespace-only text nodes are an XSLT
concept, xml:space is an XML concept, and the IsIgnorableWhitespace() method
is heaven-only-knows what!

> 3. the xml:space attribute has no effect on leading or 
> trailing whitespace, eg.
> <schedule>
> <scheduleNumber xml:space="default">    123456789</scheduleNumber>
> </schedule>

> 4. xsl:strip-space can be used to strip leading and trailing 
> whitespace in a text node, but will not affect the white 
> space ONLY text nodes.

Wrong. xsl:strip-space removes whitespace-only text nodes, it has no effect
on nodes that are not whitespace-only.
> 5. Could someone please provide an example(s) of the above, 
> including where
> exactly to put the xsl:strip-space and xsl:preserve elements.

XSLT Programmer's Reference by yours truly, pp 129-135 and 265-269.

Mike Kay

 XSL-List info and archive:

Current Thread