• Sort the nodes.

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template name="test">
        <xsl:for-each select="*">
          <xsl:sort select="/@type"/>
          <xsl:sort select="/@name"/>
          <xsl:sort select="/@type"/>
          <xsl:sort select="/@name"/>
  • Sorting can be performed on xsl:for-each and xsl:apply-template elements.

  • The primary sort-key is defined by the first xsl:sort element, subsequent xsl:sort elements define secondary and other.

  • A data-type attribute can be used to specify the type (number/text) sorting algorithm.

  • An order attribute can be used to specifies whether the nodes should be sorted in 'ascending' or 'descending' order.

  • If the data-type defined is text, a case-order attribute can be used to specify that upper-case characters should be sorted before lower-case or the other way around.

  • The test attribute value always expects a string result, the value is converted to a string as if by a call to the XPath string function.