jaxen

inverse order on preceding:: axis

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Duplicate
  • Affects Version/s: 1.1
  • Fix Version/s: 1.1
  • Component/s: jdom
  • Labels:
    None
  • Environment:
    jdom-b10, jaxen-1.1-beta-3
  • Number of attachments :
    0

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>" */ }
}

Activity

Hide
bob mcwhirter added a comment -

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

Show
bob mcwhirter added a comment - 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."
Hide
David Buchmann added a comment -

Uups, OK. I just looked up the rfc for xslt which in an example states that the order of preceding:: actually has to be inverted.

http://www.w3.org/TR/1999/REC-xpath-19991116.html#node-sets

So i guess what i reported is not a bug but the correct functioning. I interpreted the statement in the zvon.org xslt reference wrong. It actually does not say anything about the order of the returned nodes.

Show
David Buchmann added a comment - Uups, OK. I just looked up the rfc for xslt which in an example states that the order of preceding:: actually has to be inverted. http://www.w3.org/TR/1999/REC-xpath-19991116.html#node-sets So i guess what i reported is not a bug but the correct functioning. I interpreted the statement in the zvon.org xslt reference wrong. It actually does not say anything about the order of the returned nodes.
Hide
Christian Nentwich added a comment -

The counterexample is handled correctly by Jaxen. JAXEN-24 is the more severe issue

Show
Christian Nentwich added a comment - The counterexample is handled correctly by Jaxen. JAXEN-24 is the more severe issue

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: