是否可以获得用于评估 xpath 结果的所有上下文节点?在下面的代码中:
test_xml = """
<r>
<a/>
<a>
<b/>
</a>
<a>
<b/>
</a>
</r>
"""
test_root = lxml.etree.fromstring(test_xml)
res = test_root.xpath("//following-sibling::*[1]/b")
for node in res:
print test_root.getroottree().getpath(node)
结果是:
/r/a[2]/b
/r/a[3]/b
是否可以获得上述 xpath 评估中使用的所有上下文节点:
/r/a[1] /r/a[2] /r/a[2]/b
对于第二个结果:
/r/a[2] /r/a[3]/b /r/a[3]/b
? 使用子轴时,我可以从工作中获取这些节点
element_tree.getpath(elem)
但是其他轴呢?
TIA,问候