开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜