我在MarkLogic中有以下XML存储,
<testDoc>
<test>
<test1>test1</test1>
<test2>test2</test2>
<test3>test3</test3>
</test>
</testDoc>
我的要求是只获取子节点的xpath,如果我将测试(部分节点名称)传递给我的xquery然后我期待
/testDoc/test/test1
/testDoc/test/test2
/testDoc/test/test3
但是我的xquery回来了,
/testDoc
/testDoc/test
/testDoc/test/test1
/testDoc/test/test2
/testDoc/test/test3
我在qconsole上执行的XQuery是,
xquery version "1.0-ml";
let $xml := document { fn:doc("/test/testDoc")}
let $elem-name := "test"
let $elems := $xml//*[local-name()[contains(lower-case(.), lower-case($elem-name))]]
return $elems ! xdmp:path(.)
请指导我达到我的要求。
我不确定你是在尝试匹配某个深度还是只是叶子节点。如果您只想获取叶节点,可以添加谓词以检查没有子元素
[fn:not(./*)]
您还可以重写谓词并使用fn:matches()
进行匹配
let $elems := $xml//*[fn:not(./*)][fn:matches(fn:local-name(.), $elem-name, "i")]