【问题标题】:Do predicates concatenated in multiple brackets behave the same as the and operator?连接在多个括号中的谓词是否与 and 运算符的行为相同?
【发布时间】:2017-06-13 21:54:11
【问题描述】:

我正在编写一个 DOM selectors 到 xpath 转换器,碰巧如果我可以像这样连接多个谓词,它会非常适合我:

//div[@id][@class]

而不是这样:

//div[@id and @class]

虽然粗略的测试似乎表明它们的行为相同,但我并不完全确定它们在所有情况下都会。他们会吗?

【问题讨论】:

    标签: xpath predicate


    【解决方案1】:

    使用多个谓词与使用 and 运算符 100% 等效前提是两个谓词都不是位置性的。位置谓词是其值为数字的谓词,或者显式使用position()last() 的谓词。例如,*[@x][1]*[1][@x] 不同。

    【讨论】:

      猜你喜欢
      • 2022-11-30
      • 2015-05-22
      • 1970-01-01
      • 2015-08-12
      • 1970-01-01
      • 2021-01-09
      • 2020-12-18
      • 2023-03-29
      • 2014-12-19
      相关资源
      最近更新 更多