I recommend you accept Steven D. Majewski's answer, but here is the explanation (text nodes highlighted with square brackets):
<fieldset>[
]<legend>My Legend</legend>[
]<p>Some text</p>[
Text to capture
]</fieldset>
so /fieldset/text()
returns
"\n "
"\n "
"\n Text to capture\n"
And this is why you want /fieldset/text()[normalize-space()]
, and you want the result trimmed before use.
Also note that the above is short for /fieldset/text()[normalize-space(.) != '']
. When normalize-space()
returns a non-empty string, the predicate evaluates to true
, while the empty string evaluates to false
.