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. Advertising

  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. Advertising

  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. Advertising

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:
    1,976
    jan V
    Jul 29, 2005
  2. Alastair Cameron
    Replies:
    1
    Views:
    7,417
    SQL Server Development Team [MSFT]
    Jul 8, 2003
  3. Anna
    Replies:
    0
    Views:
    529
  4. goog
    Replies:
    0
    Views:
    509
  5. Navin
    Replies:
    1
    Views:
    704
    Ken Schaefer
    Sep 9, 2003
Loading...

Share This Page