How to sort values via XPath

Discussion in 'XML' started by Norbert Pürringer, Aug 24, 2009.

  1. Hello,

    does anyone know how to get a sorted list of XML nodes via XPath? I
    know the function distinct-values but I there seems to be no function
    like sorted-values.

    Thank you,
    Norbert
     
    Norbert Pürringer, Aug 24, 2009
    #1
    1. Advertisements

  2. Norbert Pürringer wrote:

    > does anyone know how to get a sorted list of XML nodes via XPath? I
    > know the function distinct-values but I there seems to be no function
    > like sorted-values.


    Pure XPath alone (at least in versions 1.0 and 2.0) does not provide any
    features to sort. However languages like XQuery or XSLT which make use
    of XPath provide features to sort, XQuery with the order by clause in
    FLWOR expressions (http://www.w3.org/TR/xquery/#id-orderby-return) and
    XSLT with the xsl:sort element (http://www.w3.org/TR/xslt20/#xsl-sort)
    and XSLT 2.0 additionally with xsl:perform-sort
    (http://www.w3.org/TR/xslt20/#creating-sorted-sequence).

    Depending on the XPath API you use there might also be sorting features
    exposed for instance in .NET's XPath's API you can use
    http://msdn.microsoft.com/en-us/library/system.xml.xpath.xpathexpression.addsort.aspx

    --

    Martin Honnen
    http://msmvps.com/blogs/martin_honnen/
     
    Martin Honnen, Aug 24, 2009
    #2
    1. Advertisements

  3. You could feed the XPath's results into your own sort routine, which is
    basically what XSLT and XPath are doing internally... (They can do it a
    bit more efficiently in most cases, but unless this is in your innermost
    loop your own sort is probably efficient enough.)
     
    Joe Kesselman, Aug 24, 2009
    #3
    1. Advertisements

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marvin_123456

    "Memory leak" in javax.xml.xpath.XPath

    Marvin_123456, Jul 29, 2005, in forum: Java
    Replies:
    4
    Views:
    2,309
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    8,182
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    769
  4. goog
    Replies:
    0
    Views:
    689
  5. Tjerk Wolterink

    XPath: efficiency in xpath expressions

    Tjerk Wolterink, Nov 13, 2004, in forum: XML
    Replies:
    1
    Views:
    2,133
    Richard Tobin
    Nov 13, 2004
  6. Replies:
    4
    Views:
    1,016
    Joseph Kesselman
    Aug 10, 2006
  7. Navin
    Replies:
    1
    Views:
    1,136
    Ken Schaefer
    Sep 9, 2003
  8. Peter Fitzgibbons

    REXML::XPath results out of sort order ?

    Peter Fitzgibbons, Oct 21, 2005, in forum: Ruby
    Replies:
    6
    Views:
    346
Loading...