The position() function is relative to the context nodeset, not the element's position in the document. Thus, when you execute the following:
node.valueOf("position()")
You're getting the position of the context node within the context, not its position within the parent. However, the position() function shouldn't return 0 according to the spec, so there's likely some problem with Jaxen, or the Node.valueOf() function. As a way of testing, see if Node.numberValueOf() returns non-zero.
The workaround you could use is the Branch.indexOf(Node) method, which gets the node index of the passed node:
int index = parent.indexOf(node);
christian.
On Jan 13, 2004, at 9:34 AM, Sven Rottenbiller wrote:
Hy Michael,
but all items/nodes are part of the document. I can ask for the parent on
each item, and I get it. All items gave me the same object, because all are
childs of the same node. So, why i get the wrong position? And why
position() says 0 and not 1?
Is there a workaround for this problem?
Sven
----- Original Message ----- From: "McDonough, Michael " <[EMAIL PROTECTED]> To: "Sven Rottenbiller" <[EMAIL PROTECTED]> Sent: Tuesday, January 13, 2004 2:53 PM Subject: RE: [dom4j-user] XPath with position()
I'm not certain, but I'll take a stab at it....is
When you selectNodes() you are returned a list with (in your example) 3
"items". Iterating to the first such item node and asking for _its_
position you get 0 because it is now the relative-root; while invoking
getUniquePath() returns the full XPath to that node with "[1]" because itin that absolute path only 1 of 3 "items".Now
_____
From: Sven Rottenbiller [mailto:[EMAIL PROTECTED] Sent: Tue 1/13/2004 6:11 To: [EMAIL PROTECTED] Subject: [dom4j-user] XPath with position()
Hallo list,
i have a xpath-problem with position(). I have a document like this:
<root> <item>1</item> <item>2</item> <item>3</item> </root>
I get a list of nodes from the document with selectNodes("/root/item").I iterate over the list and do some more xpath on every single node, andthere
here is the problem.
The following xpath says always 0 for the position. Why? node.valueOf("position()") returns 0
But when i get the unique path from the node with node.getUniquePath()
is the right position displayed. e.g.: node.getUniquePath() returns /root/item[1]
What I have to change?
Sven
------------------------------------------------------- This SF.net email is sponsored by: Perforce Software. Perforce is the Fast Software Configuration Management System offering advanced branching capabilities and atomic changes on 50+ platforms. Free Eval! http://www.perforce.com/perforce/loadprog.html <http://www.perforce.com/perforce/loadprog.html> _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user <https://lists.sourceforge.net/lists/listinfo/dom4j-user>
------------------------------------------------------- This SF.net email is sponsored by: Perforce Software. Perforce is the Fast Software Configuration Management System offering advanced branching capabilities and atomic changes on 50+ platforms. Free Eval! http://www.perforce.com/perforce/loadprog.html _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user
------------------------------------------------------- This SF.net email is sponsored by: Perforce Software. Perforce is the Fast Software Configuration Management System offering advanced branching capabilities and atomic changes on 50+ platforms. Free Eval! http://www.perforce.com/perforce/loadprog.html _______________________________________________ dom4j-user mailing list [EMAIL PROTECTED] https://lists.sourceforge.net/lists/listinfo/dom4j-user