我想在XQuery中编写以下嵌套if条件,
if(condition-1) {
if(nested-condition-11) {
....
}
if(nested-condition-12) {
....
}
}
else if(condition-2) {
if(nested-condition-21) {
....
}
if(nested-condition-22) {
....
}
}
else if(condition-3) {
if(nested-condition-31) {
....
}
if(nested-condition-32) {
....
}
}
else {
}
我尝试使用XQuery代码,
if (condition-1) then
if(nested-condition-11) then
...
else ()
if(nested-condition-12) then
...
else ()
else if (condition-2) then
if(nested-condition-21) then
...
else ()
if(nested-condition-22) then
...
else ()
else if (condition-3) then
if(nested-condition-31) then
...
else ()
if(nested-condition-32) then
...
else ()
else()
但这不起作用。它抛出以下错误,
此行的多个标记 - 第310行,第9列:无效的表达式:意外的令牌:if - 2更改了行
请分享一些指示。感谢。
答案 0 :(得分:0)
这是一个更有人工作的生产示例,它回家了:
declare namespace xf = "http://me.com/suspend/";
declare function xf:is-value-in-sequence ($value as xdt:anyAtomicType? , $seq as xdt:anyAtomicType* ) as xs:boolean
{
$value = $seq
} ;
declare function xf:checkBusinessRule($d1 as element(*), $d2 as element(*)) as element(*)
{
let $list := <results> {
for $rule at $pos in $d1//*:getBusinessCriteriaOutput
return
<temp pos="{$pos}">
<rule_id>{$rule/*:SUSPEND_RULE_ID/text()}</rule_id>
<op>{$rule/*:OPERATOR/text()}</op>
<val>{$rule/*:FIELD_VALUE/text()}</val>
</temp>
}
</results>
return <final>
{
for $a in $list//temp, $b in $d2//val
where $a/@pos = $b/@pos
return
if ($a/op = '=' and not($b/node())) then
<rec>
<rule_id>{data($a/rule_id)}</rule_id>
</rec>
else if ($a/op = '=' and fn:compare($a/val/text(), $b/text()) != 0) then
<rec>
<rule_id>{data($a/rule_id)}</rule_id>
</rec>
else if ($a/op ='LIKE' and not(fn:contains($b/text(), fn:replace($a/val/text(), '%', '')))) then
<rec>
<rule_id>{data($a/rule_id)}</rule_id>
</rec>
else if ($a/op='IN' and not(xf:is-value-in-sequence($b/text(), fn:tokenize($a/val/text(), '[,\s]+')))) then
<rec>
<rule_id>{data($a/rule_id)}</rule_id>
</rec>
else if ($a/op='NULL' and ($b/text() != '')) then
<rec>
<rule_id>{data($a/rule_id)}</rule_id>
</rec>
else if ($a/op='NOT NULL' and ($b/text() = '')) then
<rec>
<rule_id>{data($a/rule_id)}</rule_id>
</rec>
else ()
}
</final>
} ;
declare variable $d1 as element(*) external;
declare variable $d2 as element(*) external;
xf:checkBusinessRule($d1, $d2)