I have something like this:
t
The following transformation:
when applied against this XML document
txt Y
produces the wanted result:
txt A
txt X
txt Y
txt B
Do note the use of the standard XPath function normalize-space(), which strips off all leading and trailing spaces and replaces every sequence of other spaces with just one space.