Search code examples
xmlxsltlinefeedlf

Remove line feed (LF) from XML node using XSLT


I have the following in an XML node:

<TR_Comment>XXX YYY ZZZ
</TR_Comment>

(as you can see there is a line feed)

My XSLT is really simple:

<xsl:value-of select="a:Common/a:TR_Comment"/>

How can I remove the line feed using XSLT?


Solution

  • Does normalize-space(a:Common/a:TR_Comment) do what you want?

    If you are really keen on preserving inner whitespace, it can get a bit inelegant. One way is to make a recursive template that uses string-length and substring to keep removing characters from the end, one at a time, until there is no trailing whitespace.