如何使用XPath为一组元素中的selects组查找属性的最小值/最大值?

时间:2019-10-14 05:34:24

标签: xpath xpath-1.0

<foo>
  <bar id="1" score="100" group="beginner" />
  <bar id="2" score="200" group="beginner" />
  <bar id="3" score="300" group="expert" />
  ...
</foo>

我尝试这样使用,但是出了点问题(xpath 1.0)

foo/bar[@group='beginner' and not(@score<= preceding-sibling::bar/@score) and not(@score<=following-sibling::bar/@score)]

1 个答案:

答案 0 :(得分:1)

使用 xpath 1.0

/foo/bar[@group='beginner'][(not(preceding-sibling::bar[@group='beginner']/@score >= @score) and not(following-sibling::bar[@group='beginner']/@score > @score))      or (not(preceding-sibling::bar[@group='beginner']/@score <= @score) and not(following-sibling::bar[@group='beginner']/@score < @score))]/@score