Xpath 多重过滤器 select

Xpath multiple filter select

我正在尝试使用 Xpath 实现以下目标,但我无法让 selection 工作......

我有以下场景:

性别男或女 品牌名称:BrandA 或 BrandB 或 BrandC 或 BrandD

我想 select 所有 MALE 属性只有 BrandA、BrandB 和 BrandC

如果我使用以下;

/node[gender[1] = "male"] (perfect selects only the male products)

/node[gender[1] = "male" and brand[1][contains(.,"BrandA")]](perfect Xpath selects only the male products with the BrandA)

到目前为止还不错,但是如果我使用下面的站是 select 什么都没有....

/node[gender[1] = "male" and brand[1][contains(.,"BrandA")] and brand[1][contains(.,"BrandB")]]

有什么建议吗?我做错了什么?

谢谢!!

您应该在品牌名称之间使用 or 来 select 并且 and 带有性别

/node[gender[1] = "male" and 
      (brand[1][contains(.,"BrandA")] or brand[1][contains(.,"BrandB")])]

当您将 all 与 and 组合时,Xpath 找不到任何东西,因为品牌 [1] 可能同时包含品牌 A 和品牌 B