XQuery 意外如果错误
XQuery Unexpected if error
所以我正在尝试设计一个使用 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 会给出相同的错误,所以让我们保留它。
你们有没有明白我做错了什么。
我试过放置逗号和分号。那些给我其他错误,所以这不是问题。
提前致谢!
XQuery 时没有花括号if/then/else。
if (true()) then “yes” else “no”
您需要重写代码。 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
...
HTH!
所以我正在尝试设计一个使用 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 会给出相同的错误,所以让我们保留它。
你们有没有明白我做错了什么。
我试过放置逗号和分号。那些给我其他错误,所以这不是问题。
提前致谢!
XQuery 时没有花括号if/then/else。
if (true()) then “yes” else “no”
您需要重写代码。 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
...
HTH!