当“跟随”时在 XPath 中获取以下同级不支持轴

发布于 2024-09-10 05:00:36 字数 876 浏览 0 评论 0原文

我正在尝试使用 MS SQL Server 上的 XQuery 获取包含特定文本元素的段落后面的表的文本元素。问题是每当我使用“following”、“following-sibling”或“previous-sibling”轴时,我都会收到一条错误消息,指出 SQL Server 不支持此功能(我使用的是 2008 版本)。因此,例如,我可以获取包含值为“blah”的文本节点的第一个段落节点:

//w:p[descendant::w:t = "blah"]

并且我可以使用以下方法从表元素中获取文本:

//w:tbl//w:t/text()

我没有看到任何方法可以强制查询仅返回先前捕获的段落节点后面的第一个表元素,因为:

//w:tbl[following:://w:p//w:t = "blah"]//w:t/text()

给出错误:“XQuery [Specification.document.query()]:不支持 XQuery 语法‘following’。”

与以下内容相同:

//w:tbl[following-sibling::w:p[descendant::w:t = "blah"]]//w:t/text()

给出“XQuery [Specification.document.query()]:不支持 XQuery 语法‘following-sibling’”。

这是不对的,你们都知道! XPath 自 1999 年 AFAICT 1.0 起就支持跟随和跟随兄弟,因此 MS SQL Server 似乎在标准合规性方面严重不足,但无论哪种方式,有人知道我可以在没有这些轴的情况下做到这一点吗?提前致谢!

I am trying to get the text elements of a table that follows a paragraph that contains a specific text element using XQuery on MS SQL Server. The problem is whenever I use the axes "following", "following-sibling" or "previous-sibling", I get an error saying this is not supported in SQL Server (I'm using version 2008). So for instance, I can get the first paragraph node that contains a text node whose value is "blah":

//w:p[descendant::w:t = "blah"]

And I can get the text from a table element using:

//w:tbl//w:t/text()

I don't see any way I can force the query to only return the first table element that follows the previously captured paragraph node since:

//w:tbl[following:://w:p//w:t = "blah"]//w:t/text()

Gives the error: "XQuery [Specification.document.query()]: The XQuery syntax 'following' is not supported."

And the same for:

//w:tbl[following-sibling::w:p[descendant::w:t = "blah"]]//w:t/text()

Gives "XQuery [Specification.document.query()]: The XQuery syntax 'following-sibling' is not supported."

That ain't right, y'all know! XPath has supported following and following-sibling since 1.0 back in 1999 AFAICT so MS SQL Server seems to be severely deficient in terms of standard compliance but either way, does anyone see a way I can do this without those axes? Thanks in advance!

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

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

发布评论

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

评论(1

萌辣 2024-09-17 05:00:36

XQuery 中节点的文档顺序也可以使用节点比较运算符来评估。

运算符 >> 适用于两个节点,如果左侧节点按文档顺序位于右侧节点之后,则返回 true。为了解决您的问题,您需要选择第一个这样的节点。

在以下代码中,$blah$text 是给定的表达式。返回的值是 $text 中紧随 $blah 中第一个节点的第一个节点。

let $blah := //w:p[descendant::w:t = "blah"]
let $text := //w:tbl//w:t/text()
return $text[. >> $blah[1]][1]

或者,组合成一个表达式,

(//w:tbl//w:t/text()[. >> (//w:p[descendant::w:t = "blah"])[1]])[1]

Document order of nodes in XQuery can also be evaluated by using node comparison operators.

Operator >> applies to two nodes and returns true if the left hand side node follows the right hand side node in document order. For solving your problem, you'd select the first such node.

In the following code, $blah and $text are the given expressions. The returned value is the first node in $text that follows the first node in $blah.

let $blah := //w:p[descendant::w:t = "blah"]
let $text := //w:tbl//w:t/text()
return $text[. >> $blah[1]][1]

Or, combined into a single expression,

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