Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Nevertheless, the
The following example shows the correct use of
The new XSLT 2.0 option to use the sequence constructor to obtain the value, rather than the
select
attribute, is provided mainly to make
Without the outer
xs:string
. The effect of the outer
concat()
function does at the XPath level.
Avoiding Surprises
There are two situations in which
The first should be less common with XSLT 2.0 than it was with 1.0, but it will still happen in stylesheets that specify
version=“1.0”
and thus invoke backward-compatibility mode. The surprise is that only the first item in a sequence is actually output. For example, if the context node is a
version=“2.0”
: all the authors are now output, using a single space as the default separator.
Of course, if you have become accustomed to the 1.0 behavior, then the surprise might be the other way around. If your stylesheet specifies
version=“2.0”
, the output will contain all the following sibling paragraphs rather than just the first. You can easily correct this by changing it to
The second situation that sometimes causes surprise is typified by the question “Why have all the tags disappeared?” If you use
or
, then these are lost in the course of converting to a string. If you want these tags to appear in the output, then use
This situation may also change in XSLT 2.0 if you use a schema-aware processor. If the
select
expression selects an element, and the element is described in the schema as having complex element-only content, then atomization will raise a runtime error. For example if the source document contains the element:
then with a processor that is not schema-aware (or an XSLT 1.0 processor), the instruction
XSLT 2.0 Programmer's ReferenceMichael KayWiley
But with a schema-aware processor, assuming the schema declaration is:
the result will be a runtime error. If you want to concatenate the text nodes within the
With mixed content, however (where text and marked-up elements can be freely mixed in the content), it does make sense to extract the textual content without the markup, and
Examples
The table below shows some common ways in which
Instruction | Effect |
Create a text node containing the string value of the context item. | |
Create a text node containing the string values of the child | |
Create a text node containing the sum of the values of the attributes of the current node, converted to a string. If there is any non-numeric attribute, the result will be NaN or, if a schema is in use, a type error. | |
Create a text node containing the value of variable $x , after converting it to a string. |
See Also
xsl:variable
The
Changes in 2.0
A new attribute,
as
, has been introduced. This allows the type of the variable to be declared; it also determines whether an