Thank you for your response. I looked at the other results, and they did not seem to obey the xpath axis either. By using ancestor-or-self, I'm expecting an output like this: <a> <b> <c/> </b> </a> But the other results that are returned to me are: In [311]: print etree.tostring(root.xpath("/a/b/c/ancestor-or-self::*")[1], pretty_print=True) .....: <b> <c/> <x> <z/> </x> </b> In [312]: print etree.tostring(root.xpath("/a/b/c/ancestor-or-self::*")[2], pretty_print=True) .....: <c/> In [313]: print etree.tostring(root.xpath("/a/b/c/ancestor-or-self::*")[3], pretty_print=True) .....: IndexError: list index out of range On Mon, Nov 9, 2009 at 3:45 PM, Stefan Behnel <stefan_ml@behnel.de> wrote:
Polat Tuzla, 09.11.2009 14:01:
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. Thanks,
Polat Tuzla
In [309]: print etree.tostring(root, pretty_print=True) <a> <b> <c/> <x> <z/> </x> </b> </a>
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 that you only look at the first result using the "[0]" subscript, which in this case is the root node.
Stefan