<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: normalize code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Thu, 21 Aug 2008 13:31:04 GMT</pubDate>
    <description>DZone Snippets: normalize code</description>
    <item>
      <title>Normalize Space and Keep Line Breaks in XSTL</title>
      <link>http://snippets.dzone.com/posts/show/4031</link>
      <description>XSLT function pattern to normalize space but keep line breaks, without using a template.&lt;br /&gt;&lt;br /&gt;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.&lt;br /&gt;&lt;br /&gt;For reference, pretend "FieldValue/." is the path to a &lt;FieldValue&gt;foo&lt;/FieldValue&gt; element.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;translate(&lt;br /&gt; normalize-space(&lt;br /&gt;  translate(FieldValue/., '&amp;#xA;&amp;#xD;', '&amp;#xA0;&amp;#xAD;')&lt;br /&gt; ), '&amp;#xA0;&amp;#xAD;&#173;', '&amp;#xA;&amp;#xD;'&lt;br /&gt;)&lt;br /&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Thu, 17 May 2007 00:30:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4031</guid>
      <author>jokeyxero (xero)</author>
    </item>
  </channel>
</rss>
