我有这部分问题:
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()
)
};
外部循环if/then/else
中的第二个块for
不起作用。如何检查变量标志的值?我需要看看我是否通过了所有测试。
答案 0 :(得分:1)
您正在返回一个序列,因此您只需在else($flag=false())
之后添加逗号即可将其与下一个表达式分开。
答案 1 :(得分:1)
创建一系列布尔值,指示每个测试的结果,然后测试是否有任何布尔值为假。
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 ())
};
这可以简化,但我故意让它接近原文。