Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    TNO
    TNO is offline
    Regular Coder
    Join Date
    Apr 2005
    Posts
    213
    Thanks
    2
    Thanked 1 Time in 1 Post

    Counting children

    What would the xpath expression be to find the element with the most children?

    Counting is simple, removing duplicates is simple..but this one escapes me, any ideas?

  • #2
    TNO
    TNO is offline
    Regular Coder
    Join Date
    Apr 2005
    Posts
    213
    Thanks
    2
    Thanked 1 Time in 1 Post
    Ok, here's the answer on finding an element with the most immediate children:

    Code:
    //parent[count(children) >= count(following::parent/children)]/children
    You want to look at the following instead of the preceding so you don't get false positives.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •