Try a bit harder not to create empty text nodes

They get cleaned up by normalization anyway, but given that
we check for emptiness in all other places where we create
text node, we should do that consistently throughout this
function.

Change-Id: Ie0fd83bc56fbc9407b87c7c229188c6bf5336719
Merge "Try a bit harder not to create empty text nodes"