XQuery发生错误时发生意外

米克·雷默斯瓦尔

因此,我正在尝试设计一个使用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
  )

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

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

我的猜测是第二个if会给出相同的错误,因此让它保持在这个错误上。

你们有没有人知道我在做什么错。

我试过用逗号和分号隔开。这些给了我其他错误,所以这不是问题。

提前致谢!

grtjn

您需要重写代码。如果没有大括号,但是您也在中断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
...

HTH!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章