61015

how to get horizontal depth of a node?

Question:

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

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.

how can i find the maximum depth ?

Answer1:

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

/*/*/*/*//*

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

/*/*/*/*/*

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

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

Answer2:

I think that "vertical depth" and "horizontal depth" are ambiguous. Is there any reason not to use the axis terminology that already exists in XPath, and refer to "number of ancestors" and "number of preceding siblings"? It's slightly more verbose, but not much, and a) it's unambiguous and b) the terms map onto count(ancestor::*) and count(preceding-sibling::*).

Recommend

  • Getting the 'co-ordinates' of a cell using jQuery
  • Getting the inner-most row in the embedded tables
  • How can I refresh the entire table sorting cache after dynamic table update?
  • Can't get any output from the taglib
  • Add class element based on the name of the page
  • Getting proper map boundaries
  • Selenium - How to skip the record from the Set after the its first occurrence
  • why 0.1+0.2-0.3= 5.5511151231258E-17 in php [duplicate]
  • Show records ordered with maximum price first in PHP & MySQL
  • Implementation of RTTI using typeid
  • Neo4j: Legacy Indexes and auto index vs new label bases schema indexes
  • How to add learning rate to summaries?
  • d3.js selection conditional rendering
  • Why does the font in these TD elements render at different sizes?
  • garbled css name when styling within UiBinder
  • How to open html table in xls on click of a button
  • how to get username into sql trigger when multiple users signed on from asp membership
  • Custom validator control occupying space even though display set to dynamic
  • How to use remove-erase idiom for removing empty vectors in a vector?
  • Read a local file using javascript
  • Avoid links criss cross / overlap in d3.js using force layout
  • Why HTML5 Canvas with a larger size stretch a drawn line?
  • Why doesn't :active or :focus work on text links in webkit? (safari & chrome)
  • Submit form in a displaytag pagination
  • Window Size for Mac application
  • When should I choose bucket sort over other sorting algorithms?
  • ORA-29908: missing primary invocation for ancillary operator
  • How to get next/previous record number?
  • Delete MySQLi record without showing the id in the URL
  • Unanticipated behavior
  • Comma separated Values
  • How to delete a row from a dynamic generate table using jquery?
  • WPF Applying a trigger on binding failure
  • How do you join a server to an Active Directory (domain)?
  • Trying to get generic when generic is not available
  • How does Linux kernel interrupt the application?
  • How can I remove ASP.NET Designer.cs files?
  • python draw pie shapes with colour filled
  • Is there any way to bind data to data.frame by some index?
  • How can i traverse a binary tree from right to left in java?