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

|▌冷眼眸甩不掉的悲伤 提交于 2020-01-05 07:26:15

问题


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 guessing 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.


回答1:


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.



来源:https://stackoverflow.com/questions/6433065/how-to-use-the-xquery-fnidref-function

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!