如何在xquery分配中使用if-else
我试图使用if条件为xquery中的变量赋值。我不知道该怎么做 这就是我所尝试的:如何在xquery分配中使用if-else,xquery,if-statement,assignment-operator,Xquery,If Statement,Assignment Operator,我试图使用if条件为xquery中的变量赋值。我不知道该怎么做 这就是我所尝试的: declare namespace libx='http://libx.org/xml/libx2'; declare namespace atom='http://www.w3.org/2005/Atom'; declare variable $entry_type as xs:string external; let $libx_node := if ($entry_type = 'package'
declare namespace libx='http://libx.org/xml/libx2';
declare namespace atom='http://www.w3.org/2005/Atom';
declare variable $entry_type as xs:string external;
let $libx_node :=
if ($entry_type = 'package' or 'libapp') then
{element {fn:concat("libx:", $entry_type)} {()} }
else if ($entry_type = 'module') then
'<libx:module>
<libx:body>{$module_body}</libx:body>
</libx:module>'
声明名称空间libx=http://libx.org/xml/libx2';
声明名称空间atom=http://www.w3.org/2005/Atom';
将变量$entry_type声明为xs:string external;
让$libx_节点:=
如果($entry\u type='package'或'libapp'),则
{element{fn:concat(“libx:,$entry_type)}{()}
否则如果($entry_type='module'),则
'
{$module_body}
'
此代码引发[XPST0003]不完整的“if”表达式错误。有人能帮我修一下吗
另外,有人能推荐一些学习XQuery的好教程吗
谢谢,
索尼这是因为在XQuery的中,始终需要使用else表达式:
[45] IfExpr ::= "if" "(" Expr ")" "then" ExprSingle "else" ExprSingle
因此,您必须编写第二个else
子句(例如,它可能返回空序列):
声明名称空间libx=http://libx.org/xml/libx2';
声明名称空间atom=http://www.w3.org/2005/Atom';
将变量$entry_type声明为xs:string external;
让$libx_节点:=
如果($entry_type=('package','libapp')),则
元素{fn:concat(“libx:,$entry_type)}{()}
否则如果($entry_type='module'),则
{$module_body}
else()
... (这里是您的代码)。。。
还修复了一些明显的错误:
- 在计算元素构造函数周围不需要{}李>
- 最可能的情况是,您想要
if($entry\u type=('package','libapp'))
declare namespace libx='http://libx.org/xml/libx2';
declare namespace atom='http://www.w3.org/2005/Atom';
declare variable $entry_type as xs:string external;
let $libx_node :=
if ($entry_type = ('package','libapp')) then
element {fn:concat("libx:", $entry_type)} {()}
else if ($entry_type = 'module') then
<libx:module>
<libx:body>{$module_body}</libx:body>
</libx:module>
else ()
... (your code here) ...