Reputation: 503
I have this part of my query:
declare function local:accoppiamenti($snapshot){
for $ev in $snapshot/EV
let $stringa := $ev/accoppiamenti//accoppiamento/@specie
let $flag := true()
return(
if($stringa[1]=$ev/specie/@cod and $stringa[2]!=$ev/specie/@cod and $stringa[3]=$ev/specie/@cod and $stringa[last()]=$ev/specie/@cod and $stringa[last()-1]!=$ev/specie/@cod and $stringa[last()-2]=$ev/specie/@cod)
then(
for $i in (4 to count($stringa)-3)
return(
if($stringa[$i]=$ev/specie/@cod and $stringa[$i+1]!=$ev/specie/@cod and $stringa[$i+2]=$ev/specie/@cod)
then($flag=false())
else()
)
)
else($flag=false())
if($flag=true())
then(data("OK"))
else()
)
};
The second block if/then/else
in the extern cycle for
don't work. How can I check the value of the variable flag? I need to see if I passed all the tests.
Upvotes: 0
Views: 60
Reputation: 163665
Create a sequence of booleans indicating a result for each test, and then test if any of the booleans is false.
declare function local:accoppiamenti($snapshot){
for $ev in $snapshot/EV
let $stringa := $ev/accoppiamenti//accoppiamento/@specie
let $flags :=
if($stringa[1]=$ev/specie/@cod and $stringa[2]!=$ev/specie/@cod and $stringa[3]=$ev/specie/@cod and $stringa[last()]=$ev/specie/@cod and $stringa[last()-1]!=$ev/specie/@cod and $stringa[last()-2]=$ev/specie/@cod)
then(
for $i in (4 to count($stringa)-3)
return(
if($stringa[$i]=$ev/specie/@cod and $stringa[$i+1]!=$ev/specie/@cod and $stringa[$i+2]=$ev/specie/@cod)
then(false())
else(true())
)
)
else(false())
return (if every $f in $flags satisfies $f then 'ok' else ())
};
This can be simplified but I have deliberately kept it close to the original.
Upvotes: 1
Reputation: 11771
You're returning a sequence, so you just need to add a comma after else($flag=false())
to separate it from the next expression.
Upvotes: 1