开发者

Trying to simulate the XQuery function fn:idref() but without a schema

开发者 https://www.devze.com 2023-03-15 01:41 出处:网络
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;

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"]
0

精彩评论

暂无评论...
验证码 换一张
取 消