Multiple sort criteria

The list of countries example above raises an interesting problem. Having decided to sort the countries by their population figures, what happens when two countries have the same population value? By default, they are simply output in document order. In the following example, Italy and the UK have the same count, and so the order in which they appear depends entirely on the order that they occur in the source file:

<countries>
  <country>
    <name>UK</name>
    <population>58</population>
  </country>
  <country>
    <name>Italy</name>
    <population>58</population>
  </country>
</countries>

It would probably be more desirable to sort countries with the same population count into alphabetical order, thus introducing a secondary sorting requirement. ...

Get XSL companion, The 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.