我有一个 XML 片段,我想根据 id 属性的存在进行不同的查询:
<author order="1"
id="99999999"
initials="A."
given-names="Able"
surname="Baker"
fullname="Able Baker"/>
我努力了:
let $first-query := if ($first)
then cts:or-query((
cts:element-attribute-word-match(xs:QName("author"), xs:QName("given-names"), $first || "*", ("collation=http://marklogic.com/collation/codepoint")),
cts:element-attribute-word-match(xs:QName("author"), xs:QName("initials"), $first || "*", ("collation=http://marklogic.com/collation/codepoint"))
))
else ()
let $last-query := if ($last)
then cts:element-attribute-word-match(xs:QName("author"), xs:QName("surname"), $last || "*", ("collation=http://marklogic.com/collation/codepoint"))
else ()
let $author-no-id-query :=
cts:and-query((
cts:not-query(
cts:element-attribute-value-query(xs:QName("author"), xs:QName("id"), "*")
),
$first-query,
$last-query
))
let $query := cts:element-query(xs:QName("author"),
cts:or-query(($author-no-id-query, $author-id-query
)))
如果 id 存在,则发生不同的查询并匹配 id。如何检测 MarkLogic 中缺少属性?