Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
See Also
xsl:perform-sort
The
Changes in 2.0
This instruction is new in XSLT 2.0
Format
select? = expression>
Position
Attributes
Name | Value | Meaning |
select optional | XPath Expression | Returns the input sequence to be sorted. |
Content
The
In addition, it may contain a sequence constructor. This is an alternative to the
select
attribute: if the
select
attribute is present, then the
Effect
The instruction forms an initial sequence by evaluating the expression in the
select
attribute or the contained sequence constructor, whichever is present. It then sorts this initial sequence to produce a sorted sequence, according to the rules for
Usage and Examples
The
For example, you could define a global variable containing the speakers in a play, sorted alphabetically, by writing:
The following function returns the earliest and latest date in a sequence of events, as a sequence of two
date
attributes:
See Also
xsl:preserve-space
The
Changes in 2.0
The syntax of a
NameTest
has been extended to allow the format
*:NCName
, which matches all elements with a given local name, in any namespace.
Format
elements = tokens />
Position
Attributes
Name | Value | Meaning |
elements mandatory | Whitespace-separated list of NameTests | Defines the elements in the source document whose whitespace-only text nodes are to be preserved |
The
NameTest
construct is defined in XPath, and is described in Chapter 9 on page 614.
Content
None, the element is always empty.
Effect
This declaration, together with
Preserving whitespace-only text nodes is the default action, so this element only needs to be used where it is necessary to contradict an
NameTest
specified in an
NameTest
in an overriding
The concept of whitespace-only text nodes is explained in Chapter 3 (see page 144). A whitespace-only text node is a text node whose text consists
entirely
of a sequence of whitespace characters, these being space, tab, carriage return, and linefeed
(x20
,
x09
,
x0D
, and
x0A)
. The
This declaration also affects the handling of whitespace-only text nodes in any document loaded using functions such as
document()
,
doc()
, or
collection()
. It does not affect the handling of whitespace-only text nodes in the stylesheet, or in documents returned as the result of extension functions or passed to the stylesheet as the value of a stylesheet parameter. Also, the element does not affect anything that happens to the source document before the XSLT processor gets to see it, so if you create the source tree using an XML parser that strips whitespace nodes (as Microsoft's MSXML3 does, by default), then specifying
Although an XML 1.1 parser will recognize the characters
x85
and
x2028
as representing line endings, the XSLT processor will not treat these characters as whitespace. It doesn't need to, because the XML parser will have converted them into regular newline characters.
Before a node is classified as a whitespace-only text node, the tree is normalized by concatenating all adjacent text nodes. This includes the merging of text that originated in different XML entities, and also text written within CDATA sections.
A whitespace-only text node may either be stripped or preserved. If it is stripped, it is removed from the tree. This means it will never be matched, it will never be copied to the output, and it will never be counted when nodes are numbered. If it is preserved, it is retained on the tree in its original form, subject only to the end-of-line normalization performed by the XML parser.