Details
Description
Experimenting with the jdom xpath interface to jaxen, i realized that the node order returned by a preceding:: selection is inversed.
As far as i (and others: http://www.zvon.org/xxl/XSLTreference/Output/axis_preceding.html ) know, the resulting nodes of preceding:: must be "in document order".
I wrote this code that shows the issue:
import java.io.StringReader;
import java.util.List;
import org.jdom.Document;
import org.jdom.input.SAXBuilder;
import org.jdom.output.XMLOutputter;
import org.jdom.xpath.XPath;
import javax.xml.transform.*;
public class Test {
public static void main(String[] args) throws Exception {
XMLOutputter outputter = new XMLOutputter();
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(new StringReader(new String("<list><first/><entry>1</entry><entry>2</entry><entry>3</entry><last/></list>")));
XPath query = XPath.newInstance("preceding::entry");
XPath position = XPath.newInstance("//last");
List set = query.selectNodes(position.selectSingleNode(doc));
outputter.output(set, System.out);
System.out.println();
/* outputs "<entry>3</entry><entry>2</entry><entry>1</entry>" */
query = XPath.newInstance("following::entry");
position = XPath.newInstance("//first");
set = query.selectNodes(position.selectSingleNode(doc));
outputter.output(set, System.out);
System.out.println();
/* outputs "<entry>1</entry><entry>2</entry><entry>3</entry>" */
}
}
I think this is correct, though.
From the spec:
"For example, preceding::foo[1] returns the first foo element in reverse document order, because the axis that applies to the [1] predicate is the preceding axis; by contrast, (preceding::foo)[1] returns the first foo element in document order, because the axis that applies to the [1] predicate is the child axis."