获取具有 min 属性的元素 [英] Get element with min attribute

查看:28
本文介绍了获取具有 min 属性的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 Xquery,我想获取具有最小 sortOrder 的行.在下面的示例中,id=3 的行.

With Xquery I want to get the row which has the min sortOrder. In the example below the row with id=3.

<table>
  <row id="1"><attribute identifier="sortOrder">120</attribute><attribute identifier="mainContent">Test 3</attribute></row>
  <row id="2"><attribute identifier="sortOrder">130</attribute><attribute identifier="mainContent">Test 1</attribute></row>
  <row id="3"><attribute identifier="sortOrder">10</attribute><attribute identifier="mainContent">Test 2</attribute></row>
</table>

有人得到提示吗?

推荐答案

用 min() 函数找到最小值,然后在行中查找:

find min value with the min() function and then look it up in the rows:

let $min := min(//row/attribute[@identifier='sortOrder'])
return //row[attribute[@identifier='sortOrder'] = $min]

这篇关于获取具有 min 属性的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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