title: XSLT - remove whitespace from template
body: <p>I am using XML to store a small contact list and trying to write a XSL template that will transform it into a CSV file. The problem I am having is with whitespace in the output.</p>
  
  <p>The output:</p>
  
  <pre><code>Friend, John, Smith, Home,
          123 test,
         Sebastopol,
         California,
         12345,
       Home 1-800-123-4567, Personal john.smith@gmail.com
  </code></pre>
  
  <p>I have indented/spaced both the source XML file and the associated XSL Template to make it easier to read and develop, but all that extra white space is getting itself into the output. The XML itself doesn't have extra whitespace inside the nodes, just outside of them for formatting, and the same goes for the XSLT.</p>
  
  <p>In order for the CSV file to be valid, each entry needs to be on it's own line, not broken up. Besides stripping all extra white space from the XML and XSLT (making them just one long line of code), is there another way to get rid of the whitespace in the output?</p>
  
  <p>Edit:
  Here is a small XML sample:</p>
  
  <pre><code>&lt;PHONEBOOK&gt;
      &lt;LISTING&gt;
          &lt;FIRST&gt;John&lt;/FIRST&gt;
          &lt;LAST&gt;Smith&lt;/LAST&gt;
          &lt;ADDRESS TYPE="Home"&gt;
              &lt;STREET&gt;123 test&lt;/STREET&gt;
              &lt;CITY&gt;Sebastopol&lt;/CITY&gt;
              &lt;STATE&gt;California&lt;/STATE&gt;
              &lt;ZIP&gt;12345&lt;/ZIP&gt;
          &lt;/ADDRESS&gt;
          &lt;PHONE&gt;1-800-123-4567&lt;/PHONE&gt;
          &lt;EMAIL&gt;john.smith@gmail.com&lt;/EMAIL&gt;
          &lt;RELATION&gt;Friend&lt;/RELATION&gt;
      &lt;/LISTING&gt;
  &lt;/PHONEBOOK&gt;
  </code></pre>
  
  <p>And here is the XSLT:</p>
  
  <pre><code>&lt;?xml version="1.0" ?&gt;
  &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  &lt;xsl:output method="text" /&gt;
  
   &lt;xsl:template match="/"&gt;
     &lt;xsl:for-each select="//LISTING"&gt;
      &lt;xsl:value-of select="RELATION" /&gt;&lt;xsl:text&gt;, &lt;/xsl:text&gt;
      &lt;xsl:value-of select="FIRST" /&gt;&lt;xsl:text&gt;, &lt;/xsl:text&gt;
      &lt;xsl:value-of select="LAST" /&gt;&lt;xsl:text&gt;, &lt;/xsl:text&gt;
  
      &lt;xsl:if test="ADDRESS"&gt;
       &lt;xsl:for-each select="ADDRESS"&gt;
         &lt;xsl:choose&gt;
          &lt;xsl:when test="@TYPE"&gt;
           &lt;xsl:value-of select="@TYPE" /&gt;,
          &lt;/xsl:when&gt;
              &lt;xsl:otherwise&gt;
              &lt;xsl:text&gt;Home &lt;/xsl:text&gt;
              &lt;/xsl:otherwise&gt;
         &lt;/xsl:choose&gt;
         &lt;xsl:value-of select="STREET" /&gt;,
         &lt;xsl:value-of select="CITY" /&gt;,
         &lt;xsl:value-of select="STATE" /&gt;,
         &lt;xsl:value-of select="ZIP" /&gt;,
       &lt;/xsl:for-each&gt;
      &lt;/xsl:if&gt;
  
      &lt;xsl:for-each select="PHONE"&gt;
        &lt;xsl:choose&gt;
         &lt;xsl:when test="@TYPE"&gt;
          &lt;xsl:value-of select="@TYPE" /&gt;  
         &lt;/xsl:when&gt;
         &lt;xsl:otherwise&gt;&lt;xsl:text&gt;Home &lt;/xsl:text&gt;&lt;/xsl:otherwise&gt;
        &lt;/xsl:choose&gt;
       &lt;xsl:value-of select="."  /&gt;&lt;xsl:text  &gt;, &lt;/xsl:text&gt;
      &lt;/xsl:for-each&gt;
  
      &lt;xsl:if test="EMAIL"&gt;
       &lt;xsl:for-each select="EMAIL"&gt;
        &lt;xsl:choose&gt;
         &lt;xsl:when test="@TYPE"&gt;
          &lt;xsl:value-of select="@TYPE" /&gt;&lt;xsl:text  &gt; &lt;/xsl:text&gt; 
         &lt;/xsl:when&gt;
         &lt;xsl:otherwise&gt;&lt;xsl:text  &gt;Personal &lt;/xsl:text&gt;&lt;/xsl:otherwise&gt;
        &lt;/xsl:choose&gt;
        &lt;xsl:value-of select="."  /&gt;&lt;xsl:text  &gt;, &lt;/xsl:text&gt;
       &lt;/xsl:for-each&gt;
      &lt;/xsl:if&gt;
      &lt;xsl:text&gt;&amp;#10;&amp;#13;&lt;/xsl:text&gt;
     &lt;/xsl:for-each&gt;
   &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>