如何使用XQuery fn:idref()函数? [英] How to use the XQuery fn:idref() function?

查看:148
本文介绍了如何使用XQuery fn:idref()函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法获得XQuery函数fn:idref()返回任何内容.

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

我有这个XML文档 doc.xml ;

I have this XML document doc.xml;

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

这个XQuery;

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

但是结果始终为空.我猜想属性idref="xyz"需要声明为类型idref,但是可以在没有模式的情况下完成吗?

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?

我正在使用Saxon XQuery 1.0处理器.

I'm using Saxon XQuery 1.0 processor.

推荐答案

是的,idref()函数仅检索标记为IDREF的属性,并且仅在架构验证的情况下发生.

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

有一个过时的旧设置config.setRetainDTDAttributeTypes()允许它作为DTD验证的结果而工作,但我不会使用它.

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.

您始终可以执行doc("doc.xml")//*[@idref="xyz"].这将导致在Saxon-HE和Saxon-PE中进行串行搜索,但是将使用Saxon-EE中的索引.我通常会推荐使用idref()函数.

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.

当然,在XSLT中,您可以使用键.

In XSLT, of course, you can use keys.

这篇关于如何使用XQuery fn:idref()函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆