
Hi Thibault, On Thu, 26 Nov 2015 09:16:13 +0100 Thibault Clerice <leponteineptique@gmail.com> wrote:
Thanks for the explanation, I tried to find the documentation about XPath 1 and Xpath 2 to ensure this was not due to that, but could not find the needle in the haystack.
Me neither.
Unfortunately, I cannot use the syntax you gave, but I found two alternatives, one being given to me by someone on the list in a private mail (Jamie):
- //div//*[local-name()='p' or local-name()='l'][@n='1'] - //div//*[lself::ns:p or self::ns:l][@n='1']
Just to make it clear: the first expression matches *all* 'p' and 'l' elements regardless to which namespace they belong. This may or may not what you want. Probably this works in most cases, but you should be aware of that if you have a mixture of different elements from different namespaces this will be an issue.
Work both terribly well. In case anyone is like me, stuck with not so much ability to go the /a/a | /a/b road.
Another solution would be to avoid XPath and use lxml/Python. You can iterate through your tree, maybe something like this:
NS = "{YOUR_NAMESPACE}" tree = etree.parse("some.xml") root = tree.getroot() alldivs = [i for i in root.iterdescendants("{}div".format(NS)) ] all_l_p = [i for d in alldivs for i in d.iterdescendants() \ if i.tag in ("{}p".format(NS), "{}l".format(NS)) ]
Of course you need to filter the additional 'n' attribute too, but I hope the idea is clear. -- Gruß/Regards, Thomas Schraitle