XML technologies / XSLT / Introduction to XSLT 2.0 / Getting started with XSLT and XPath / A comparison: expression vs. instruction / Variant 2: The XPath-oriented approach
(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, Chapter 1.)
If compatibility with XSLT 1.0 is not required, you can directly take advantage of sequence processing by xsl:value-of. Here, this is done by supplying the instruction with a slightly more complex XPath expression. Instead of using simple XPath expressions and several XSLT instructions as before, the approach is reversed.
Warning:
A XSLT processor, which supports only XSLT 1.0 and XPath 1.0, cannot process this example and will report an error!
So far, the instruction has always received just one node to extract its string value. This lets you control the output order directly through the arrangement of the xsl:value-of instructions, but it also uses up one instruction for each element to be output.
As already indicated, xsl:value-of can do more: it can extract the string value not only of a single expression, but of an entire sequence of input expressions. If the XPath expression in the select attribute produces a sequence, the return value is the concatenation of the string values of its individual items. (Note: Admittedly, a small detail has been omitted here for teaching purposes. Please be patient :-).)
Instead of several instructions each selecting a particular node, you can therefore use a single instruction with a tailor-made input sequence. But where does that sequence come from?
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from "XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch" is subject to the same terms as the printed edition: the work and all its parts are protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn