Simple element sorting

One good example of the need to sort elements is the task of creating a glossary. In the following example, the Glossary element contains a number of Item elements, which have not been arranged in any particular order:

<glossary>
  <item>XSL - ...</item>
  <item>XML - ...</item>
  <item>SGML - ...</item>
  <item>HTML - ...</item>
</glossary>

Using techniques described previously, it would be possible to convert this data into an equivalent HTML structure. However, as elements are normally processed in document order, the output shown below is in the same order as the source XML items:

<DIV>
  <P>XSL - ...</P>
  <P>XML - ...</P>
  <P>SGML - ...</P>
  <P>HTML - ...</P>
</DIV>

The Sort element can be used to override this default ordering. ...

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.