本文介绍了如何获得节点的水平深度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

注意我编造了术语水平深度来测量树中节点的子维度.

note i made up the term horizontal depth to measure the sub-dimension of a node within a tree.

所以想象一个 xpath 类似于/html/table/tbody/tr/td 和 5 的水平深度"

so imagine a which would have xpath something like /html/table/tbody/tr/td, and "horizontal depth" of 5

我想看看是否有办法根据这个水平深度来识别和选择元素.

i am trying to see if there is a way to identify and select elements based on this horizontal depth.

如何找到最大深度?

推荐答案

如果你需要所有深度 >= 5 的节点:

If you need all the nodes with depth >= 5:

/*/*/*/*//*

如果你需要所有深度 == 5 的节点:

And if you need all the nodes with depth == 5:

/*/*/*/*/*

其实有一个XPath函数count,你可以结合ancestor轴:

Actually, there is a XPath function count, which you can combine with ancestor axis:

//*[count(ancestor::*) >= 4]

这篇关于如何获得节点的水平深度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-12 17:39