如何使用XPath获取整个min属性?

时间:2019-05-20 11:24:05

标签: xml xpath

我想使用XPath获取属性。

shouldComponentUpdate()

我现在想获得2,因为在第二个礼物中id最小。有人有主意吗?

谢谢

2 个答案:

答案 0 :(得分:0)

使用XPath-2.0最简单。
试试这个表情

/GetTest/Result[id = min(/GetTest/Result/id)]

选择所有具有最小值的Result元素。

答案 1 :(得分:0)

在XPath 1.0中,最小成语是:

$node-set[not(. > $node-set)]
  

“选择不大于其他节点的节点”

因此,要获得相对位置,您需要对兄弟姐妹进行计数,例如:

count(/GetTest/Result/id[not(. > ../../Result/id)]/../preceding-sibling::Result) + 1

签入http://www.xpathtester.com/xpath/aab60fddde5c48b013efff791b9f11c9