How do I return ” for an empty node’s text() in XPath?

While @Tomalak is perfectly right, in XPath 2.0 one can use:

//td/string(.)

and this produces a sequence of strings — each one containing the string value of a corresponding td element.

So, in your case the result will be the desired one:

"", "foo"

Leave a Comment