gpt4 book ai didi

xml - 如何使用 XPath 查找一组元素中某个属性的最小值?

转载 作者:数据小太阳 更新时间:2023-10-29 01:37:55 25 4
gpt4 key购买 nike

如果我有这样的 XML:

<foo>
<bar id="1" score="192" />
<bar id="2" score="227" />
<bar id="3" score="105" />
...
</foo>

我可以使用 XPath 找到 score 的最小值和最大值吗?

编辑:我正在使用的工具(Andariel ant 任务)不支持 XPath 2.0 解决方案。

最佳答案

这是一个稍微简短的解决方案。

最大值:

/foo/bar/@score[not(. < ../../bar/@score)][1]

最低:

/foo/bar/@score[not(. > ../../bar/@score)][1]

我编辑了谓词,使其适用于 bar 的任何序列,即使您决定更改路径。请注意,属性的父级是它所属的元素。

如果将这些查询嵌入到 XSLT 或 ant 脚本等 XML 文件中,请记住编码 <>作为&lt;尊重&gt; .

关于xml - 如何使用 XPath 查找一组元素中某个属性的最小值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1128745/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com