elements, with the same parent node, calling XPathUtils.findPath(to, from, context) will always return an xpath expression pointing to the same node index.
text
The reason is because XPathUtils function getPeerPositionPredicate(node, context) compares the contents of XML elements to determine the node index. Instead, it should compare the "childIndex" of the XML element.
Here's a fixed version of the function:
private static function getPeerPositionPredicate(node:XML, context:XPathContext):String
{
var parent:XML = node.parent();
if(!parent){
return "";
}
var peers:XMLList = node.parent()[node.name()];
var n:int = peers.length();
var i:int = 0;
if (n > 1){
var nodeIndex:int = node.childIndex();
for(; i < n; ++i){
if (nodeIndex == peers[i].childIndex())
break;
}
}
return "[" + (context.zeroIndexPosition ? i : ++i) + "]";
}
From tra...@circutus.com on October 05, 2011 09:55:41
Given two identical
elements, with the same parent node, calling XPathUtils.findPath(to, from, context) will always return an xpath expression pointing to the same
node index.
The reason is because XPathUtils function getPeerPositionPredicate(node, context) compares the contents of XML elements to determine the node index. Instead, it should compare the "childIndex" of the XML element.
Here's a fixed version of the function:
private static function getPeerPositionPredicate(node:XML, context:XPathContext):String { var parent:XML = node.parent(); if(!parent){ return ""; }
var peers:XMLList = node.parent()[node.name()]; var n:int = peers.length(); var i:int = 0; if (n > 1){ var nodeIndex:int = node.childIndex(); for(; i < n; ++i){ if (nodeIndex == peers[i].childIndex()) break; } } return "[" + (context.zeroIndexPosition ? i : ++i) + "]"; }
Original issue: http://code.google.com/p/xpath-as3/issues/detail?id=26