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
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.
Thanks, Sony