-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
<?xml-stylesheet ?>
element breaks relative xpaths
#81
Comments
Hi, elementpath.select(root1, query, fragment=True))
# returns [<Element second at ... >] Anyway the behavior may be not as intended by the argument description:
so something have to be fixed, at least when fragment is thank you |
A fix for fragment argument usage is available with v4.7.0. The default is changed to For default the root node kind is not changed, except the cases like xml1 with lxml, where an effective document part is added, if you not provide This default behavior with lxml could be changed, but with the drawback that root siblings can't be selected (in this case an explicit Waiting for a feedback on this or close the issue. Thank you |
Just to be clear. Given an XML containing a PI. If I want to use a relative query starting from the root (e.g. import elementpath
from lxml import etree
xml = b"""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type='text/xsl' href='test.xsl'?>
<root>
<first>
<second>
value
</second>
</first>
</root>
"""
root = etree.XML(xml)
relative_query = "first/second"
root_query = "//root"
elementpath.select(root, relative_query, fragment=True)
root.xpath(relative_query)
# both return the same element now thanks to the fragment changes
elementpath.select(root, root_query, fragment=True)
# returns []
root.xpath(root_query)
# returns [<Element root at ...>] |
Hi, If you have to use both relative and absolute paths a solution is to provide import elementpath
from lxml import etree
xml = b"""<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type='text/xsl' href='test.xsl'?>
<root>
<first>
<second>
value
</second>
</first>
</root>
"""
root = etree.XML(xml)
relative_query = "first/second"
root_query = "//root"
res1 = elementpath.select(root, relative_query, item=root)
res2 = root.xpath(relative_query)
assert res1 == res2 == [root[0][0]]
# both returns [<Element second at ...>]
res1 = elementpath.select(root, root_query, item=root)
res3 = elementpath.select(root, root_query)
res2 = root.xpath(root_query)
assert res1 == res2 == res3 == [root]
# all returns [<Element root at ...>] |
The same XPath query with a relative path from the root child node does not return results if there is a
<?xml-stylesheet ?>
tag present in the XML document.Minimal repro code:
Is that expected? Why is it happening?
The text was updated successfully, but these errors were encountered: