Strange results of xpath element search using string-value

Алексей Алексей schrieb am 29.09.2017 um 23:12:
Can't understand the results of the following xpath queries: /from lxml import etree/ /from io import StringIO/ /s = '<aaa><bbb>f<ccc>e</ccc>d</bbb></aaa>'/ /tree = etree.parse(StringIO(s))/ /print(tree.xpath('//bbb[.="fed"]')) #Returns nothing/ /print(tree.xpath('//bbb[contains(.,"fed")]')) #Returns bar/ /print(tree.xpath('//bbb[normalize-space(.)="fed"]')) #Returns bar/ /print(tree.xpath('//bbb[string-length(.)=3]')) #Returns bar/ The first query doesn't find bar element by its string-value while the other three surprisingly do. Suppose that it is a bug.
According to how I read the spec, that looks like a bug.
""" The string-value of an element node is the concatenation of the string-values of all text node descendants of the element node in document order. """
https://www.w3.org/TR/xpath/#element-nodes
However, the XPath implementation is in libxml2, not in lxml. Please report the bug over there. Using xmllint instead of lxml usually helps them:
$ echo '<aaa><bbb>f<ccc>e</ccc>d</bbb></aaa>' | \ xmllint --xpath '//bbb[. = "fed"]' - XPath set is empty
$ echo '<aaa><bbb>f<ccc>e</ccc>d</bbb></aaa>' | \ xmllint --xpath '//bbb[string() = "fed"]' - <bbb>f<ccc>e</ccc>d</bbb>
Stefan
participants (2)
-
Stefan Behnel
-
Алексей Алексей