Specifies sort criteria for node lists selected by xsl:for-each or xsl:apply-templates.
<xsl:sort select = string-expression data-type = { "text" | "number" | Qname } order = { "ascending" | "descending" } />
"text" | Specifies that the sort keys should be sorted alphabetically. |
number | Specifies that the sort keys should be converted to numbers and then sorted according to the numeric value. The sort key is converted to a number. |
QName | Expanded into a dt-expanded-name. The expanded-name identifies the data type. |
If no data type is specified, the type of the expression will be used as the default.
Number of occurrences | Unlimited |
Parent elements | xsl:apply-templates, xsl:for-each |
Child elements | (No child elements) |
Inherent data types (from XML Schema) are supported in the following manner:
For example, suppose an employee database has the form
<employees> <employee> <name> <given>James</given> <family>Clark</family> </name> ... </employee> </employees>
Then a list of employees sorted by name could be generated using:
<xsl:template match="employees"> <ul> <xsl:apply-templates select="employee"> <xsl:sort select="name/family"/> <xsl:sort select="name/given"/> </xsl:apply-templates> </ul> </xsl:template> <xsl:template match="employee"> <li> <xsl:value-of select="name/given"/> <xsl:text> </xsl:text> <xsl:value-of select="name/family"/> </li> </xsl:template>