使用 XPath 1.0 查找最大子计数 [英] Find the maximum child count with XPath 1.0

查看:29
本文介绍了使用 XPath 1.0 查找最大子计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能否找到一个 XPath 子节点最多的 XML 节点?

Can I find one XML node with the most children with XPath?

<xml>
  <node id="1">
    <child />
  <node>
  <node id="2">
    <child /><child />
  <node>
  <node id="3">
    <child /><child />
  <node>
  <node id="4">
    <child /><child /><child />
  <node>
  <node id="5">
    <child /><child /><child />
  <node>
</xml>

我想使用单个纯 XPath 1.0 表达式选择节点 4 或节点 5.

I would like to select either node 4 or node 5 with a single, pure XPath 1.0 expression.

推荐答案

我认为这是不可能的,因为你需要函数 count() 有一个参数 - node-set 并返回此集合中的元素计数.因此,您无法选择如何计算多于一个的节点集以获得最大值.

I think that it is impossible because to count children you need function count() which has one parameter - node-set and returns count of elements in this set. So you have no option how to count more node-sets than one to get max value.

注意:我说的是 XPath 1.0

Note: I am talking about XPath 1.0

这篇关于使用 XPath 1.0 查找最大子计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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