xsl:perform-sort


xsl:perform- sort

The <xsl:perform-sort> instruction is used to sort a sequence. If you want to process the items in a sequence in sorted order, you can achieve this by adding <xsl:sort> elements to an <xsl:apply-templates> or <xsl:for-each> instruction. If you just want to sort the sequence, without processing the items individually, this can be done using <xsl:perform-sort> .

Changes in 2.0

This instruction is new in XSLT 2.0

Format

 <xsl:perform-sort   select? = expression   <!-- Content: (xsl:sort+, sequence-constructor) --> </xsl:sequence> 

Position

<xsl:perform-sort> is an instruction, and may be used anywhere within a sequence constructor.

Attributes

Name

Value

Meaning

select

optional

Expression

Returns the input sequence to be sorted

Content

The <xsl:perform-sort> instruction always contains one or more <xsl:sort> elements to specify the sort order.

In addition it may contain a sequence constructor. This is an alternative to the select attribute: If the select attribute is present, then the <xsl:perform-sort> element must contain only <xsl:sort> elements. It can also contain <xsl:fallback> elements to define what an XSLT 1.0 processor should do when it encounters this instruction in forwards-compatible mode.

Effect

The instruction forms an initial sequence by evaluating the expression in the select attribute or the contained sequence constructor, whichever is present. It then sorts this initial sequence to produce a sorted sequence, according to the rules for <xsl:sort> which are given on page 423. The result of the <xsl:perform-sort> instruction is the sorted sequence.

Usage and Examples

The <xsl:perform-sort> instruction is useful when you want to create a sorted sequence in a variable, or as the result of a function. If you want to process items in sorted order you can achieve this using <xsl:for-each> or <xsl:apply-templates>, but these instructions do not deliver the sorted sequence directly as a value in its own right.

For example, you could define a global variable containing the speakers in a play, sorted alphabetically , by writing:

  <xsl:variable name="sorted-speakers" as="xs:string*">   <xsl:perform-sort select="distinct-values(//SPEAKER)">   <xsl:sort select="."/>   </xsl:perform-sort>   </xsl:variable>  

The following function returns the earliest and latest date in a sequence of dates, as a sequence of two dates:

  <xsl:function name="f:first-and-last">   <xsl:param name="in" as="xs:date*"/>   <xsl:variable name="sorted-dates" as="xs:date*">   <xsl:perform-sort select="$in">   <xsl:sort select="."/>   </xsl:perform-sort>   </xsl:variable>   <xsl:sequence select="$sorted-dates[1], $sorted-dates[last()]"/>   </xsl:function>  

See Also

  • <xsl:apply-templates> on page 187

  • <xsl:for-each> on page 276

  • <xsl:sort> on page 423




XSLT 2.0 Programmer's Reference
NetBeansв„ў IDE Field Guide: Developing Desktop, Web, Enterprise, and Mobile Applications (2nd Edition)
ISBN: 764569090
EAN: 2147483647
Year: 2003
Pages: 324

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net