开发者

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

I can't get the XQuery function fn:idref() to return anything.

I have this XML document doc.xml;

<doc>
  <foo idref="xyz"/>
  <bar xml:id="xyz"/>
</doc>

And this XQuery;

let $d := doc("doc.xml")
return $d/idref("xyz")

But the result is always empty. I'm gues开发者_StackOverflow中文版sing that the attribute idref="xyz" needs to be declared as type idref but can that be done without a schema?

I'm using Saxon XQuery 1.0 processor.


Yes, the idref() function only retrieves attributes labelled as being IDREFs, and that only happens as a result of schema validation.

There's a deprecated legacy setting config.setRetainDTDAttributeTypes() that allows it to work as a result of DTD validation, but I wouldn't use it.

You can always do doc("doc.xml")//*[@idref="xyz"]. This will result in a serial search in Saxon-HE and Saxon-PE, but will make use of an index in Saxon-EE. I would generally recommend this over using the idref() function.

In XSLT, of course, you can use keys.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜