This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
Well, sure. Whenever you are trying to select nodes which satisfy a particular condition, you would put that condition into an XPath predicate. And I believe XPath has a count() function: you could look that up.
However both the "td" elements in your example have five descendants which are text. Not four, there's a whitespace text node in both cases. So comparing the number of text descendants wouldn't help in this caswe.