I want to look for a specific node in a Response XML, and return true or false, depending on if it matches a condition. How can I do it in order to only receive a unique node response and not as many as elements the XML contains?
Here is my Xquery code:
for $recordRetrieved in $sA_ADS_VerifOutput1/ns0:recordRetrieved
return
if ($recordRetrieved/ns0:COD_NRBE_EN = $ent and
$recordRetrieved/ns0:DAT <= $dat)
then <ns2:func>{ true() }</ns2:func>
else <ns2:func>{ false() }</ns2:func
with this code, if the XML contains 3 elements $sA_ADS_VerifOutput1/ns0:recordRetrieved
the response will be (for instance):
<ns2:func>false</ns2:func>
<ns2:func>false</ns2:func>
<ns2:func>true</ns2:func>
I don't want this, but if all are false, I expect <ns2:func>false</ns2:func>
and if at least one is true I expect <ns2:func>true</ns2:func>
, only one time.
I thought about using the where
clause, but I need to emerge false if no elemet meets the condition.
Thanks.
You want:
some $recordRetrieved in $sA_ADS_VerifOutput1/ns0:recordRetrieved
satisfies ($recordRetrieved/ns0:COD_NRBE_EN = $ent and
$recordRetrieved/ns0:DAT <= $dat)
or more simply
exists($sA_ADS_VerifOutput1/ns0:recordRetrieved[
ns0:COD_NRBE_EN = $ent and ns0:DAT <= $dat])