尝试模拟 XQuery 函数 fn:idref() 但没有模式

发布于 2024-11-16 18:00:22 字数 627 浏览 4 评论 0原文

我想在 XML 文档中搜索具有包含特定 id 的 idrefs 属性的元素。例如,给定此 XML 文档 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>

我想要这个 XQuery;

let $d := doc("doc.xml")
return $d/local:getref("hello")

返回该元素;

<x2 idrefs="world hello"/>

我相信 fn:idref() 正是这样做的,但前提是 doc.xml 具有适当的架构。这可以在没有模式的情况下完成吗?

我正在使用 Saxon XQuery 处理器。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

从﹋此江山别 2024-11-23 18:00:22

这似乎与

如何使用 XQuery fn:idref 有关() 函数?

没有架构,您需要

//*[tokenize(@idrefs, ' ') = "hello"]

This seems to be related to

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

Without a schema, you need

//*[tokenize(@idrefs, ' ') = "hello"]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文