View Full Version : Counting children

11-13-2008, 10:54 PM
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?

11-17-2008, 03:28 PM
Ok, here's the answer on finding an element with the most immediate children:

//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.