kol*_*kol 1 xml xpath xquery marklogic
我试图找到xml中每个元素的xpath并将其作为元素值.我的源文件看起来像:
<root>
<parent1>
<child1></child1>
<child2></child2>
</parent1>
<parent2>
<child1></child1>
</parent2>
</root>
Run Code Online (Sandbox Code Playgroud)
我想要一个输出像:
<root>
<parent1>
<child1> /root/parent1/child1 </child1>
<child2> /root/parent1/child2 </child2>
</parent1>
<parent2>
<child1> /root/parent2/child1 </child1>
</parent2>
</root>
Run Code Online (Sandbox Code Playgroud)
我目前得到的输出为:
<root>
<parent1>
<child1> /root/parent1/child1 </child1>
<child2> /root/parent1/child2 </child2>
</parent1>"
<parent2>
<child1> /root/parent1/parent2/child1 </child1>
</parent2>
</root>
Run Code Online (Sandbox Code Playgroud)
我无法正确遍历以找到xpath.任何输入都是有价值的.
我建议使用xdmp:path,也许是这样的:
declare function local:add-paths($nodes) {
for $node in $nodes
return
typeswitch ($node)
case element()
return element { node-name($node) } {
$node/@*,
if ($node/node()) then
local:add-paths($node/node())
else
xdmp:path($node)
}
default
return $node
};
let $xml :=
<root>
<parent1>
<child1></child1>
<child2></child2>
</parent1>
<parent2>
<child1></child1>
</parent2>
</root>
return local:add-paths($xml)
Run Code Online (Sandbox Code Playgroud)
HTH!
| 归档时间: |
|
| 查看次数: |
559 次 |
| 最近记录: |