xquery:查找父节点是否具有不同命名空间的子节点 [英] xquery: find if a parent node has a child node of a different namespace
问题描述
我正在尝试检查名称空间X"的节点是否具有不同名称空间Y"的子节点.我尝试了以下 xquery:
I am trying to check if a node of namespace 'X' has a child node of a different namespace 'Y'. I tried the following xquery:
declare namespace atom = "http://www.w3.org/2005/Atom";
declare namespace libx = "http://libx.org/xml/libx2";
let $doc := <node><entries xmlns="http://www.w3.org/2005/Atom" xmlns:libx="http://libx.org/xml/libx2">
<libx:book-entry><book>Book 1</book><author>Author 1 PQR</author><title>Title 1</title></libx:book-entry>
<libx:car-entry><car>Car 1</car><model>Model 1</model><price>Price 1 PQR</price></libx:car-entry>
</entries></node>,
$types := <types xmlns="http://libx.org/xml/libx2"><type>book-entry</type></types>,
$key := 'PQR'
for $type in $types/libx:type
return
for $entry in $doc/atom:entries/*[name() eq $type]
return $entry
我希望结果是:
.但是,查询返回 null,因为 name 函数没有考虑不同的命名空间.除了 name() 之外,是否还有另一个 xquery 函数,它接受一个命名空间参数,它会给出所需的结果.
I expect the result to be: <libx:book-entry><book>Book 1</book><author>Author 1 PQR</author><title>Title 1</title></libx:book-entry>
. But, the query returns null as the name function does not take into account a different namespace. Is there another xquery function apart from name() which takes in a namespace parameter which would give the desired result.
谢谢,索尼
推荐答案
您可以使用 local-name()
函数来匹配元素的本地名称(正如您在 <强>$types).
You could use the local-name()
function to match just the elements' local names (as you have listed them in $types).
或者,如果您想具体一点,可以组合使用 local-name()
和 namespace-uri()
函数来匹配元素名称和命名空间 URI.
Or if you wanted to be really specific, a combination of the local-name()
and namespace-uri()
functions to match both element name and Namespace URI.
这篇关于xquery:查找父节点是否具有不同命名空间的子节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!