KsAig
KsAig

Reputation: 3

Return one true/false when checking multiple items in XQuery

<Response>
    <List>
        <item>
            <Date>2019-01-01</Date>
        </item>
        <item>
            <Date>2020-01-11</Date>
        </item>
        <item>
            <Date>2021-03-01</Date>
        </item>
    </List>
</Response>

I try to get one false / true in an expression in XQuery, but it only works for every value.

let $Dates := //Response/List/item[*]/Date
for $Date in $Dates
return if ( $Date>='2020-01-01' and $Date<='2021-01-01') 
then true
else false

Result:

false
true
false

There was also an attempt to do so:

let $Date := //Response/List/item[*]/Date
return 
fn:boolean($Date>='2019-01-01' and $Date<='2019-12-31')

In this case, returns false only if all elements do not satisfy the check.

p.s: This is planned to be used in Assertions in SoapUI, so if you have other solutions, please write too.

p.s2: I apologize for my English, I use a translator.

Upvotes: 0

Views: 681

Answers (1)

Yitzhak Khabinsky
Yitzhak Khabinsky

Reputation: 22275

You need to use Quantified Expressions.

Check it out here: XQuery/Quantified Expressions

Along the following.

XPath

every $Date in /Response/List/item/Date/text()
satisfies ($Date>='2020-01-01' and $Date<='2021-01-01') 

Upvotes: 2

Related Questions