如何使用Xpath 1.0从XML文档中找到max属性 [英] How to find the max attribute from an XML document using Xpath 1.0

查看:298
本文介绍了如何使用Xpath 1.0从XML文档中找到max属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以使用Xpath 1.0查询XML文档以返回给定属性的最大值?

Is there a way to query an XML document to return the maximum of a given attribute using Xpath 1.0 ?

例如,有没有一种方法可以获取最大ID?

For example is there a way to get the max id ?

<?xml version="1.0" encoding="utf-8"?>
<library>
        <book id="2" name="Dragon Tatoo"/>
        <book id="7" name="Ender's Game"/>
        <book id="3" name="Catch 22"/>
        <book id="1" name="Lord of the rings"/>
</library>

推荐答案

在XPath 2.0中,使用max函数.要找到id最高的书,请

In XPath 2.0, use the max function. To find the book with the highest id, do

/library/book[@id = max(/library/book/@id)]

这篇关于如何使用Xpath 1.0从XML文档中找到max属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆