9.4. The <xsl:sort> Element

The <xsl:sort> element is used to reorder each node in the current node-set prior to processing the node list further with instruction elements. The current node-set for <xsl:sort> is the list of nodes returned from the select attribute of either <xsl:apply-templates> or <xsl:for-each>. Technically, <xsl:sort> is not classified as an instruction element because it is only allowed within two specific elements: <xsl:apply-templates> and <xsl:for-each>. The <xsl:sort> element is empty and has five optional attributes, as shown in the following element model definition. The main attribute is select, which contains an expression used as the key for sorting the node list.

<xsl:sort

  select = string-expression

  lang = { 

Get XSLT and XPATH: A Guide to XML Transformations 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.