sort

sort is used in conjunction with apply-templates and foreach to determine the order in which they should process the selected nodes.

Syntax
<sort> ::= "sort" ( "using" <expression> )? ( "lang" <expression> )? ( "ascending" | "descending" )? ( "upper-first" | "lower-first" )? ( "text" | "number" )?
Options
using an XPath expression indicating the node and children to match.
ascending/descending* specifies the processing order.
upper-first/lower-first* specifies whether upper or lower case take precedence in the ordering.
lang specifies the language to be used for the sort.
text-sort/number-sort* specifies whether ordering should be done alphabetically or numerically.

* specifies default value

Note that the name of the options text-sort and number-sort are to avoid conflict with the reserved word text and number.

Elements

None.

Examples

For example

stylesheet { version "1.0" proc output-variable-index { foreach "//aw:definitions/aw:define" { sort using "@var" upper-first } } }

compiles to

<stylesheet xmlns="http://www.w3.org/1999/XSL/Transform" version="1.0"> <template name="output-variable-index"> <for-each select="//aw:definitions/aw:define"> <sort select="@var" case-order="upper-first"/> </for-each> </template> </stylesheet>
Errors

sort statements should occur directly after the item they are refering to. For example

stylesheet { version "1.0" proc output-variable-index { foreach "//aw:definitions/aw:define" { value "'Some text'" sort using "@var" upper-first } } }

would give an error

**** (141) Sort in "foreach://aw:definitions/aw:define" in line 7 must follow declaration. Check order.
Copyright 2024 Hugh Field-Richards. All Rights Reserved.