在XPath中,如何检查列表是否包含特定项?

时间:2011-08-16 15:52:09

标签: dom xpath tokenize

我需要在xpath中有一个包含函数的列表,它的工作原理如下:

//*[contains( ("one", "two", "three"), "one")

有这样的东西吗?

仅针对上下文,这是我要解决的问题:

我有一个DOM树

<element blah="one two three">

<element blah="bone two three">

<element blah="two three one">

我想选择第一个和第三个,因为它们包含一个。

//*[contains(tokenize(@blah,'\s+'),'one')]

这是我到目前为止所做的,但它似乎不是一个有效的XPath查询。

我知道tokenize以这种格式返回一些内容:

("one", "two", "three")

我需要的是能够检查该列表中的内容。

1 个答案:

答案 0 :(得分:1)

简单:

"one" = ("one", "two", "three")

或者更冗长:

some $i in ("one", "two", "three") satisfies $i eq "one"
相关问题