搜索节点的奇怪错误 MarkLogic

Strange Error MarkLogic searching through nodes

我在 QueryConsole 中遇到问题

当我尝试 运行 时:

xquery version "1.0-ml";
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 $factValues :=
  for $doc in /xbrli:xbrl
      let $factValue := $doc//xs:QName("bd-bedr:WageTaxDebt")
      let $docId := $doc//xbrli:identifier/text()
      where $docId eq "11"
            return $factValue/text()

return $factValues

引号之间的字符串来自仅提供字符串的输入

我收到这个错误:

[1.0-ml] XDMP-NOTANODE: (err:XPTY0019) $factValue/text() -- "bd-bedr:WageTaxDebt" is not a node
Stack Trace
At line 19 column 21:
In xdmp:eval("xquery version &quot;1.0-ml&quot;;&#10;&#10;declare namespace li...", (), <options xmlns="xdmp:eval"><database>11967107844575880929</database>...</options>)
$doc := fn:doc("document76.xml")/xbrli:xbrl
$factValue := ("bd-bedr:WageTaxDebt", "bd-bedr:WageTaxDebt", "bd-bedr:WageTaxDebt", ...)
$docId := fn:doc("document76.xml")/xbrli:xbrl/xbrli:context/xbrli:entity/xbrli:identifier/text()
17. let $docId := $doc//xbrli:identifier/text()
18. where $docId eq "11"
19. return $factValue/text()
20. 
21. return $factValues

我知道字符串不是节点,但是转换为 QName 不应该解决这个问题吗?

有谁知道我做错了什么,先谢谢了!

如您所知,您不能写:

let $factValue := $doc//xs:QName("bd-bedr:WageTaxDebt")

XPath 表达式最好写成:

let $factValue := $doc//bd-bedr:WageTaxDebt

虽然您在寻找动态 XPath,但这使它变得有点棘手。使用普通的 XPath 你可以这样做:

let $factValue := $doc//*[name() eq xs:QName("bd-bedr:WageTaxDebt")]

但这可能会非常慢,尤其是当您的 XML 文档很大时。一种更高效的方法可能是:

let $factValue := xdmp:value("$doc//" || xs:QName("bd-bedr:WageTaxDebt"))

但是,这会带来代码注入的风险,因此您必须仔细验证输入,例如将转换保持为 xs:QName

然而,最好的方法可能是使用 xdmp:unpath:

let $factValue := xdmp:unpath("$doc//" || "bd-bedr:WageTaxDebt")

HTH!