Hi,
I'm observing that xpath axis "ancestor-or-self" does not function properly. Below outputs demonstrate the case. In the first one whole tree is printed, and in the second one ancestor-or-self is used, but the result does not differ.
I'll open a ticket for this as a bug, unless someone tells me that I'm missing a point.
You're missing a point :)
In [309]: print etree.tostring(root, pretty_print=True) <a> <b> <c/> <x> <z/> </x> </b> </a>
Ok, so you print out root here.
In [310]: print etree.tostring(root.xpath("/a/b/c/ancestor-or-self::*")[0], pretty_print=True) .....: <a> <b> <c/> <x> <z/> </x> </b> </a>
Note how you print out root again, now:
root.xpath("/a/b/c/ancestor-or-self::*") [<Element a at 266930>, <Element b at 2668a0>, <Element c at 266960>] root.xpath("/a/b/c/ancestor-or-self::*")[0] is root True
xpath() returns a list of elements in this case, of which you select the first item - which is root. ancestor-or-self is a forward axis and the position of nodes in a forward axis is defined in terms of document order: See the Xpath Rec: 2.4 Predicates [...] Thus, the ancestor, ancestor-or-self, preceding, and preceding-sibling axes are reverse axes; all other axes are forward axes. [...] The proximity position of a member of a node-set with respect to an axis is defined to be the position of the node in the node-set ordered in document order if the axis is a forward axis and ordered in reverse document order if the axis is a reverse axis. The first position is 1. Holger -- DSL-Preisknaller: DSL Komplettpakete von GMX schon für 16,99 Euro mtl.!* Hier klicken: http://portal.gmx.net/de/go/dsl02