I have the following Xquery:
let $x := <a>
<i>false</i>
</a>
return
if (every $t in $x/a satisfies $t/i eq "true")
then $x
else <nothing/>
How I interpret this is, return $x if all <a> have an <i> that has the word "true". However, this always return $x.
In contrast, if I have the following XML doc:
<root>
<a><i>false</i></a>
</root>
and the following query:
for $x in /root
return
if (every $t in $x/a satisfies $t/i eq "true" )
then $x
else <nothing/>
It will return <nothing/> when <i> contains false and will return $x when <i> is "true"
My questions are:
The key difference is the existence of a root element assigned to $x in the second example, but not in the first.
In your first example the root element is <a>, but in your quantifier expression you write every $t in $x/a. $x/a selects child a elements of <a>, and there are none (only i). So $x/a evaluates to empty. The expression is reduced to every $t in () satisfies $t/i eq "true". Since empty is assigned to $t the full quantifier expression evaluates to true.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With