我想在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更改行
请分享这方面的一些建议。谢谢。
发布于 2015-05-01 21:20:06
我认为问题是然后-表达式和其他表达式必须是单表达式。
因此,您现在拥有的内容类似于这样(不是实际的XQuery代码):
if (condition) then
if statement <-- first expression
if statement <-- second expression
else
()您需要做的是将表达式包装在括号中,并用逗号分隔它们。基本上创造一个序列..。
if (condition) then
(if statement, if statement) <-- one expression
else
()这就是您的示例的最终结果(为可读性添加了额外的换行符):
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 () 发布于 2015-05-04 20:04:15
下面是一个更有针对性的生产示例:
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)https://stackoverflow.com/questions/29992386
复制相似问题