xpath多条件并返回root

时间:2012-10-19 11:18:44

标签: xpath conditional-statements exist-db

是否可以在xpath中执行'和'条件,如

//foo/bar/test[@val='hello'] and //foo/bar/new[@val='world']

由于某种原因,此条件返回true,而不是任何结果。我试过了|,但我不需要or声明。

结果应该返回// foo中的所有元素(条件匹配的地方) - 我需要根元素,因为我将从不同的元素中提取数据。

我正在使用xpath来查询exists-db数据库

我还需要将//foo[(position()> 3) and (position() < 6)]放在那里。

1 个答案:

答案 0 :(得分:4)

如果您想获取foo元素,请在[]之后foo开始:

//foo[bar/test/@val='hello' and bar/new/@val='world']

如果您想要foo的孩子,请将括号放在那里:

//foo/bar[test/@val='hello' and new/@val="world"]
相关问题