Normalize Space And Keep Line Breaks In XSTL
Join the DZone community and get the full member experience.Join For Free
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( normalize-space( translate(FieldValue/., ' ', ' ') ), ' Â', ' ' )
Opinions expressed by DZone contributors are their own.