Grouping Made Even Simpler
Now for the fun part. You can accomplish the same sort of grouping demonstrated in the last example with the for-each-group
statement using only an expression. Here's another way to group the costs:
select="for $x in /products/prices/price[name =
$name], $y in self::* return $x/cost" />
Examine the expression in the select attribute and you can see that it's the equivalent of the for-each-group
statement shown earlier. You can find the code for this alternate grouping scheme in the file Listing5.xsl, which is included in the downloadable sample code
for this article.
XSLT 2.0 addresses many of the concerns XSLT developers have raised. It turns grouping into a simple and directly manageable task, reduces the dependence on extensive recursive templates for string manipulation routines, deals with the issue of node-set access, and introduces the notion of multiple output documents, to name just a few.
Whether these new capabilities will result in broader usage remains to be seen. Although it's natural to think that some developers will look at XQuery as a competing language for XML processing, I tend to think the oppositethat widespread adoption of XQuery will actually expose more
people to XSLT, because they're both so closely linked to XPath.
The two languages serve different purposes. XSLT was never intended to be a query language, although people have used it that way for lack of alternatives. XQuery is not intended to be a transformation language, but should see substantial use as a querying tool or application-level interface, particularly within the scope of native XML data sets in databases.
I haven't covered every new feature of XSLT 2.0 in this article. For a more complete list, see Elliotte Rusty Harold's slide presentation
introducing XSLT 2.0, XPath 2.0, and XQuery.