Get the non-empty element using XPATH
It actually can be simplified as below:
//group/p1[string-length() > 0] => element text is non-empty
//group/p1[string-length() = 6] => element text has length 6
This xpath should work as well:
//group/p1[string-length(text()) > 0]
You may also use [not(node())]
Selector.
Example: //group/p1[not(node())]
How about something like /root/group/p1[text() and not(../following-sibling::group/p1/text())]
In other words: get the p1 elements that have text and whose group parents are not followed by group nodes that have non-empty p1 elements.