Multiple Sorts

When you use multiple xsl:sort elements, you put the major sort criterion first, then the next most important, and so on if you are using more than two sort criteria.

The xsl:sort element must be a direct child element of the xsl:apply-templates element (in this example). It is an error to nest xsl:sort elements inside each other.

Listing 12.8 shows the XSLT stylesheet modified so that it outputs all (here, both) the final documents first, but those final documents are themselves sorted in ascending alphabetical order.

Listing 12.8. Documents4.xsl: Applying Two Sorts to the Source Document
<?xml version='1.0'?> 
<xsl:stylesheet 
 version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
  > 
<xsl:output method="html" indent="yes" ...

Get Sams Teach Yourself XML in 10 Minutes now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.