Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/elixir/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在xquery分配中使用if-else_Xquery_If Statement_Assignment Operator - Fatal编程技术网

如何在xquery分配中使用if-else

如何在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'

我试图使用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' 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'))
关于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','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) ...