sissaschool/elementpath

Second argument of 'index-of' method doesn't evaluate to element content

Elucin opened this issue · 2 comments

Here is a piece of test code I'm working with:

from lxml import etree as ET
import elementpath

root = ET.fromstring("""<root>
    <incode>030</incode>
    <descript></descript>
</root>""")

test1 = "/root/descript[index-of(('030','031'), '030')]"
test2 = "/root/descript[ancestor::root/incode = '030']"
test3 = "/root/descript[index-of(('030','031'), ancestor::root/incode)]"

assert len(elementpath.select(root, test1)) == 1
assert len(elementpath.select(root, test2)) == 1
assert len(elementpath.select(root, test3)) == 1

test1 uses a literal string and finds the index in the list. As expected, it works fine and selects the element.
test2 is meant to prove that ancestor::root/incode does indeed return the expected value of '030'.
But then I get to test3, which should give the same results as test1 given that ancestor::root/incode = '030' is true, but instead I get an assert error, as the length of the selection is 0.

So I know that ancestor::root/incode gives the right value, but not when contained within the index-of method. (at least, I haven't tried it with other methods, but it may not be exclusive to the index-of method.)

I'm using Python 3.8.0

Hi,

this was due to the missing of usage of the data value of the 2nd argument. I've changed using a call for getting the atomized operand (returns the data value of the element and check cardinality). The fix will be available with the release v2.0.0.

Thanks

Release v2.0.0 is available in PyPI