The sort key should be an expression that returns a different result for each node in the node list to be sorted. Because your expression starts with "//", its value is the same for all nodes. Try the expression "." instead.
Also please note, Saxon's XPath implementation is much more efficient when you apply it to a native Saxon tree rather than a DOM.
Michael Kay

From: [] On Behalf Of Srikanth Vittal
Sent: 17 June 2008 16:10
Subject: [saxon] XPath and setSortKey - Does not work for me

Hi Guyz

I am trying to use setSortKey to sort the xpath result. But, the output is not sorted!!! This is what I tried:

    // BufferPosition is a tag, and I want the output to be sorted based on the text content of this tag

    Document node = parser.parse("xml/test.xml");

    XPathExpressionImpl xei = (XPathExpressionImpl) xpath.compile("//BufferPosition");
    XPathExpressionImpl sortKey = (XPathExpressionImpl) xpath.compile("//BufferPosition/text()");
    NodeList xpath_value = (NodeList) xei.evaluate(node, XPathConstants.NODESET);

Any idea? Please help.