Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
The
elements
attribute of
NameTests
. The form of a
NameTest
is defined in the XPath expression language; see Chapter 9, page 614. Each form of
NameTest
has an associated priority. The different forms of
NameTest
and their meanings are:
The priority is used when conflicts arise. For example, if the stylesheet specifies:
then whitespace-only text nodes appearing within a
NameTest
in the latter has higher priority (0 as compared to –0.5).
If there is an
In deciding whether to strip or preserve a whitespace-only text node, only its immediate parent element is considered in the above rules. The rules for its other ancestors make no difference. The element itself, of course, is never removed from the tree: the stripping process will only remove text nodes.
Regardless of the
xml:space=“preserve”
, then all descendant text nodes are preserved, unless this is cancelled by
xml:space=“default”
. If an
xml:space
attribute with a default value of
preserve
. There is no way of overriding this in the stylesheet.
The
Usage
For many categories of source document, especially those used to represent data structures, whitespace- only text nodes are never significant, so it is useful to specify:
which will remove them all from the tree. There are two main advantages in stripping these unwanted nodes:
Generally speaking, it is a good idea to strip whitespace-only text nodes belonging to elements that have element content, that is, elements declared in the DTD as containing child elements but no
#PCDATA
, or declared in a schema to have a complex type with
mixed=“no”
.
By contrast, stripping whitespace-only text nodes from elements with mixed content (elements declared in the DTD or schema to contain both child elements and
#PCDATA
) is often a bad idea. For example, consider the element below:
He went to
The space between the
College
and
Oxford
will run together.