'或' XPath 谓词中的运算符?

发布于 2024-08-20 15:06:43 字数 456 浏览 4 评论 0原文

用于选择 元素的 XPath 表达式是什么type="application/rss+xml" OR type="application/atom+xml"(RSS 和 Atom 提要)

  • 链接[@rel='alternate'][@type='application/rss+xml'] 选择 RSS feed
  • link[@rel='alternate'][@type='application/atom+xml' ] 选择 Atom feeds

但是用于选择它们的单个 XPath 表达式是什么?

谢谢。

What is the XPath expression to select <link> elements with type="application/rss+xml" OR type="application/atom+xml" (RSS and Atom feeds)

  • link[@rel='alternate'][@type='application/rss+xml'] selects RSS feeds
  • link[@rel='alternate'][@type='application/atom+xml'] selects Atom feeds

But what is the single XPath expression for selecting them both?

Thank you.

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

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

发布评论

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

评论(2

那小子欠揍 2024-08-27 15:06:43

使用:

link[@rel='alternate'][@type='application/rss+xml' or @type='application/atom+xml'] 

参见 http://www.w3.org/TR/xpath/#NT- OrExpr

您也可以使用 union 来完成此操作,

link[@rel='alternate'][@type='application/rss+xml']|link[@rel='alternate'][@type='application/atom+xml']

or 也可以。

use:

link[@rel='alternate'][@type='application/rss+xml' or @type='application/atom+xml'] 

see http://www.w3.org/TR/xpath/#NT-OrExpr

You could also use union to accomplish this

link[@rel='alternate'][@type='application/rss+xml']|link[@rel='alternate'][@type='application/atom+xml']

but or will do.

木落 2024-08-27 15:06:43

如果您想使用 XPath 2.0,则像这样编写会更优雅(但可能会造成混乱,具体取决于谁可能正在阅读代码):

link[@rel='alternate'][@type = ('application/rss+xml', 'application/atom+xml')] 

这样做的原因是 XPath 2.0 重新定义了 '=' 以应用于序列,这意味着如果在比较左侧序列中的项目与比较右侧序列中的项目时存在一个匹配项,则上述比较返回 true。如果您想要比较的事物列表是动态的,这会非常有用。

if you want to get fancy and use XPath 2.0, it is more elegant (but potentially confusing, depending who might be reading the code) to write it like this:

link[@rel='alternate'][@type = ('application/rss+xml', 'application/atom+xml')] 

the reason for this is that XPath 2.0 redefines '=' to apply to sequences, which means that the above comparison returns true if there is one match when comparing items from the left-hand sequence with comparing items from the right-hand sequence. this can be very useful if the list of things you want to compare with is dynamic.

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