用于具有最小值的循环

时间:2014-09-03 11:38:07

标签: xml xquery

我获得了以下XML代码,并希望按属性标识sort_order对其进行排序。

<products>
 <product>
  <row>
   <attribute identifier="SORT_ORDER">60100</attribute>
  </row>
  <row>
   <attribute identifier="SORT_ORDER">60104</attribute>
  </row>
 </product>
 <product>
  <row>
   <attribute identifier="SORT_ORDER">400</attribute>
  </row>
  <row>
   <attribute identifier="SORT_ORDER">398</attribute>
  </row>
 </product>
</products>

到目前为止,我在Get element with min attribute

的帮助下尝试了什么
for $a in //products/product 
order by number ( $a/row[attribute[@identifier='sortOrder']=string(min(//attribute[@identifier='SORT_ORDER']) ) ]/attribute[@identifier='SORT_ORDER'])
return $a

但是上面代码的输出就像输入一样。没有错误。 这里出了什么问题?

1 个答案:

答案 0 :(得分:2)

for $a in //products/product 
   order by min ($a//attribute[@identifier='SORT_ORDER'])
return $a
相关问题