XPath多个属性值中的一个,条件为

问题描述:

给出以下表达式,如何使用=可以更简洁明确?XPath多个属性值中的一个,条件为

(//h2/@id[contains(.,"foo") or contains(.,"bar") or contains(.,"baz"))[last()] 

这是我尝试过,但我解释说,这是无效的:

(//h2/@id[text() = ("foo", "bar", "baz")])[last()] 

我不能使用,因为我需要防范的子字符串匹配。我正在使用XPath 1.0和an answer to a related question是这个问题的动力。

在XPath 2.0,

//h2[@id = ("foo", "bar", "baz")][last()] 

将选择文档中最后h2元件用的foobar,或baz一个id属性值。

在XPath 1.0,你会使用显式布尔or运营商:

//h2[@id="foo" or @id="bar" or @id="baz"][last()] 
+1

和高个,用于提供的XPath 2.0当量。太感谢了!! –