1

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.

Nigel Alderton
  • 2,265
  • 2
  • 24
  • 55

1 Answers1

3

This seems to be related to

How to use the XQuery fn:idref() function?

Without a schema, you need

//*[tokenize(@idrefs, ' ') = "hello"]
Community
  • 1
  • 1
Michael Kay
  • 156,231
  • 11
  • 92
  • 164