home contribute faq download

FunctX XSLT Functions

functx:sort

Sorts a sequence of values or nodes

Google
Webxsltfunctions.com

Description

The functx:sort function sorts a sequence of values or nodes. If nodes are provided, their typed values are compared (if they are untyped, they are treated like strings.) Although this can easily be accomplished with an order by clause, calling this function makes the query less verbose because you can avoid writing a FLWOR expression solely to sort the values.

Arguments and Return Type

NameTypeDescription
$seq item()* the sequence to sort
return value item()*

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:sort" as="item()*"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="seq" as="item()*"/>

   <xsl:for-each select="$seq">
     <xsl:sort select="."/>
     <xsl:copy-of select="."/>
   </xsl:for-each>

</xsl:function>

Examples

<xsl:variable name="in-xml" as="item()*">
<in-xml>
  <f>c</f>
  <f>a</f>
  <e>b</e>
</in-xml>
</xsl:variable>
XPath ExampleResults
functx:sort(('c','a','b'))
('a', 'b', 'c')
functx:sort($in-xml/*)
<f>a</f>
<e>b</e>
<f>c</f>

See Also

functx:sort-as-numericSorts a sequence of numeric values or nodes
functx:sort-case-insensitiveSorts a sequence of values or nodes regardless of capitalization
functx:sort-document-orderSorts a sequence of nodes in document order

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Datypic XSLT Services

Recommended Reading:

XQuery