xsl:sort Element (Windows CE 5.0)
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" }
lang = { nmtoken }
case-order = { "upper-first" | "lower-first" }
/>
Attributes
select
Specifies a sort key for the node. An expression that is evaluated with the specified node as the current node and with the complete list of nodes being processed in unsorted order as the current node-list. The resulting object is converted to a string that is used as the sort key for that node. The default value of the select attribute is"."
. This causes the string-value of the current node to be used as the sort key.data-type
Specifies the data type of the strings. The following values are allowed.String Meaning "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.
order
Specifies whether the strings will be sorted in ascending or descending order. The default is "ascending".case-order
Specifies whether the strings will be sorted with lower-case or uppercase characters specified first. The default is "upper-first".lang
Specifies which language's alphabet is used to determine sort order. If no lang value is specified, the language is determined from the system environment.
Element Information
Number of occurrences | Unlimited |
Parent elements | xsl:apply-templates, xsl:for-each |
Child elements | (No child elements) |
Example
For example, suppose an employee database has the following form.
<employees>
<employee>
<name>
<given>Frank</given>
<family>Pellow</family>
</name>
...
</employee>
</employees>
A list of employees sorted by name could be generated using the following.
<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>
See Also
Send Feedback on this topic to the authors