How to sort values via XPath

N

Norbert Pürringer

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
 
M

Martin Honnen

Norbert said:
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
 
J

Joe Kesselman

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top