There are potentially multiple ways to do this. One of which is using XPaths, but perhaps it's just simpler to use a descendants iterator and a StringBuilder, and a check on the ancestry of each text node....
For example (and I'm typing in by hand, not validating this...):
public String getTitleText(final Element title) {
final StringBuilder sb = new StringBuilder();
for (final Text txt : title.getDescendants(Filters.text())) {
final Element parent = txt.getParentElement();
if (parent == title ||
parent.getAttributeValue("active", "not").equals("true")) {
sb.append(txt.getValue());
}
}
return sb.toString();
}