Over a million developers have joined DZone.

Normalize Space And Keep Line Breaks In XSTL

DZone's Guide to

Normalize Space And Keep Line Breaks In XSTL

· ·
Free Resource
XSLT function pattern to normalize space but keep line breaks, without using a template.

It replaces both line break characters with non-whitespace placeholders, normalizes, then puts the line breaks back in, nothing fancy. Note that it will handle all four types of line breaks (LF, CR, CRLF, LFCR) even though only LF is XML standard. In our case, the placeholders are characters 160 and 173, the hard space and soft hyphen respectively. They're used, but generally only by programmers and Office documents.

For reference, pretend "FieldValue/." is the path to a 

  translate(FieldValue/., '

', ' ­')
 ), ' ­Â­', '



Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}