I want to search an XML document for the element that has an idrefs
attribute containing a specific id
. For example, given this XML document doc.xml
;
<doc>
<x1 idrefs="foo bar">
<x2 idrefs="world hello"/>
</x1>
<x3 idrefs="ipsum lepsum"/>
<a xml:id="bar"/>
<b xml:id="hello"/>
</doc>
I want this XQuery;
let $d := doc("doc.xml")
return $d/local:getref("hello")
to return this element;
<x2 idrefs="world hello"/>
开发者_如何学编程
I believe that fn:idref()
does exactly this, but only if doc.xml
has an appropriate schema. Can this be done without a schema?
I'm using the Saxon XQuery processor.
This seems to be related to
How to use the XQuery fn:idref() function?
Without a schema, you need
//*[tokenize(@idrefs, ' ') = "hello"]
精彩评论