XQuery 如果在输入处理期间发生错误,则出现意外情况

Mic*_*aal 2 xml xquery marklogic

我正在尝试设计一个利用 MarkLogic 查询控制台和 MarkLogic 数据库的简单应用程序。

我的代码如下所示:

declare namespace link="http://www.xbrl.org/2003/linkbase";
declare namespace bd-alg="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-algemeen";
declare namespace bd-bedr="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-bedrijven";
declare namespace bd-bedr-tuple="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-bedr-tuples";
declare namespace bd-dim-mem="http://www.nltaxonomie.nl/nt11/bd/20161207/dictionary/bd-domain-members";
declare namespace bd-dim-dim="http://www.nltaxonomie.nl/nt11/bd/20161207/validation/bd-axes";
declare namespace xbrldi="http://xbrl.org/2006/xbrldi";
declare namespace xbrli="http://www.xbrl.org/2003/instance";
declare namespace iso4217="http://www.xbrl.org/2003/iso4217";
declare namespace xlink="http://www.w3.org/1999/xlink";

let $startDateInput := ""
let $endDateInput := ""

if($startDateInput)
  {
    then let $startDate := xs:date($startDateInput)
    else let $startDate := xs:date("1900-01-01")
  }
  
if($endDateInput)
  {
    then let $endDate := xs:date($endDateInput)
    else let $endDate := xs:date("2100-12-31")
  }
    
for $doc in /xbrli:xbrl
    let $docId := $doc/xbrli:context//xbrli:identifier/text()
    let $docStartDate := xs:date($doc//xbrli:startDate/text())
    let $docEndDate := xs:date($doc//xbrli:endDate/text())
    where $docStartDate >= $startDate and $docEndDate <= $endDate    
    order by $docStartDate, $docId + 1  
  return 
  (
    $docId,
    $docStartDate,
    $docEndDate
  )
Run Code Online (Sandbox Code Playgroud)

我收到的错误是此操作的意外错误

if($startDateInput)
  {
    then let $startDate := xs:date($startDateInput)
    else let $startDate := xs:date("1900-01-01")
  }
Run Code Online (Sandbox Code Playgroud)

我的猜测是,第二个 if 会给出相同的错误,所以让我们保留这个错误。

你们中有人明白我做错了什么吗?

我尝试过放置逗号和分号。这些给了我其他错误,所以这不是问题。

提前致谢!

grt*_*tjn 5

你需要重写你的代码。if 没有大括号,但您也中断了 FLWOR 语句的逻辑。请记住,XQuery 是一种函数式语言。做这样的事情:

let $startDateInput := ""
let $endDateInput := ""

let $startDate :=
    if($startDateInput)
    then xs:date($startDateInput)
    else xs:date("1900-01-01")

let $endDate :=
    if($endDateInput)
    then xs:date($endDateInput)
    else xs:date("2100-12-31")

for $doc in /xbrli:xbrl
...
Run Code Online (Sandbox Code Playgroud)

哈!