How to reemplace new line( \n ) for comma and space (', ') XPATH 1.0

315 Views Asked by At

I have the next string:

AAAAAAA
BBBBBBB BBBBBBB
CCCCCCC CCCCCCC

I would like to have the next string:

AAAAAAA, BBBBBBB BBBBBBB, CCCCCCC CCCCCCC

Thank you if you could help my I only could do it with XPATH 1.0.

1

There are 1 best solutions below

1
On

In XPath 1.0 we have to rely on translate() along with normalize-space() instead of the handy replace():

translate(normalize-space(/),' ',',')

Online Demo

The downside of this approach is we can only translate to a single character, so no extra space after the comma. But for all intents and purposes, this should be cosmetic only.