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

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

问题描述

我第一次尝试让 fn:id() XQuery 函数做某事时失败了.

I'm failing in my first attempt to get the fn:id() XQuery function to do something.

到目前为止,我有一个名为 bar.xml 的文档;

So far I have a document called bar.xml;

<bar>
    <foo id="a"/>
    <foo id="b"/>
    <foo id="c"/>
</bar>

还有一个 XQuery;

And an XQuery;

doc('bar.xml')/fn:id(("a", "c"))

但我尝试的一切似乎都返回了一个空集.

But everything I try just seems to return an empty set.

我还没有学习 XML 模式.fn:id() 可以在不为 bar.xml 声明单独模式文件的情况下工作吗?

I have yet to learn XML schemas. Can fn:id() work without declaring a separate schema file for bar.xml?

推荐答案

需要说明你的id属性是ids.

You need to indicate that your id attributes are ids.

执行此操作的一种方法是将模式或 DTD 添加到指定此内容的文档中.

One way to do this is to add a schema or DTD to the document that specifies this.

另一种(更简单的)方法是在文档中使用 xml:id 代替 id.

The other (far easier) way is to use xml:id in place of id in your document.

在相关说明中,您可能希望使用 element-with-id() 而不是 id().element-with-id() 做了 id() 最初打算做的事情,并且 id 出于兼容性原因保留在规范中.

On a related note, you may wish to use element-with-id() instead of id(). element-with-id() does what id() was originally intended to do, and id remains in the specification for compatibility reasons.

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

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