On 5/23/2023 11:35 AM, Shuxin Li wrote:
Hi,
I'm Shuxin. Recently I came across this test case in which BaseX returned counterintuitive result. From my feelings it seems like a bug but the behavior of Saxon is similar, and therefore is hard for me to confirm. Give XML document
<P1 id="1"><A1 id="2">1</A1><A1 id="3">1</A1>1</P1>
and XPath query
//*[boolean(.) cast as xs:double]
Both Saxon and BaseX return the result node set [1, 2]. However, the nodes with id 2 and 3 seems identical to me and is hard to understand why node 2 is selected while 3 is not. If node 2 is deleted from the XML document, result set [1,3] is returned. I'm interested in whether this is intended behavior which I might have limited knowledge of? If it is also of interest for you you may have a look. Thank you very much!
boolean(.) in a predicate of a node will always be true, so what you have is
//*[true() cast as xs:double]
which is
//*[1]
which is
/descendant-or-self::node()/*[1]
and that holds for the outer P element being the first child of the document node and for the A1 id="2" element being the first child of the P element.
If you remove the first A1, then the previously second child is now the first child *[1] of the P and therefore selected as well.
So in my view the result of Saxon and BaseX is fine.