title: Confusing whitespace issue in XSLT
body: <p>I have two versions of a document encoded in one TEI XML and wish to output one of the versions to a text file. Here’s the sample XML:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml" schematypens="http://relaxng.org/ns/structure/1.0"?&gt;
  &lt;?xml-model href="http://www.tei-c.org/release/xml/tei/custom/schema/relaxng/tei_all.rng" type="application/xml"
  schematypens="http://purl.oclc.org/dsdl/schematron"?&gt;
  &lt;TEI xmlns="http://www.tei-c.org/ns/1.0"&gt;
    &lt;teiHeader&gt;
        &lt;fileDesc&gt;
           &lt;titleStmt&gt;
              &lt;title&gt;Title&lt;/title&gt;
           &lt;/titleStmt&gt;
           &lt;publicationStmt&gt;
              &lt;p&gt;Publication Information&lt;/p&gt;
           &lt;/publicationStmt&gt;
           &lt;sourceDesc&gt;
              &lt;p&gt;Information about the source&lt;/p&gt;
           &lt;/sourceDesc&gt;
        &lt;/fileDesc&gt;
    &lt;/teiHeader&gt;
    &lt;text&gt;
        &lt;body&gt;
           &lt;p&gt;John Q Doe was born in 
              &lt;app&gt;
                 &lt;rdg wit="text1"&gt;Omaha&lt;/rdg&gt;
                 &lt;rdg wit="text2"&gt;Lincoln&lt;/rdg&gt;
              &lt;/app&gt;
          in 1950. But was he
              &lt;app&gt;
                 &lt;rdg wit="text1"&gt;happy&lt;/rdg&gt;
                 &lt;rdg wit="text2"&gt;glad&lt;/rdg&gt;
              &lt;/app&gt;?
          Some say no.
           &lt;/p&gt;
        &lt;/body&gt;
    &lt;/text&gt;
  &lt;/TEI&gt;
  </code></pre>
  
  <p>And here’s the sample XSLT:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:tei="http://www.tei-c.org/ns/1.0" xmlns:xs="http://www.w3.org/2001/XMLSchema"
  exclude-result-prefixes="xs tei" version="2.0"&gt;
  
      &lt;xsl:output omit-xml-declaration="yes" method="text" encoding="UTF-8"/&gt;
  
      &lt;xsl:template match="text()"&gt;
          &lt;xsl:value-of select='normalize-space()'/&gt;
      &lt;/xsl:template&gt;
  
  
      &lt;xsl:template match="/"&gt;
          &lt;xsl:apply-templates&gt;&lt;/xsl:apply-templates&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="tei:teiHeader"&gt;
      &lt;/xsl:template&gt;
  
      &lt;xsl:template match="tei:app"&gt;       
          &lt;xsl:apply-templates/&gt;
      &lt;/xsl:template&gt;
  
  
      &lt;xsl:template match="tei:rdg[@wit='text1']"&gt;
          &lt;xsl:apply-templates/&gt;
      &lt;/xsl:template&gt;
  
  
      &lt;!-- Cancel out the alternate version of the text--&gt;
      &lt;xsl:template match="tei:rdg[@wit='text2']"&gt;
      &lt;/xsl:template&gt;
  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>What I want to output is “John Q Doe was born in Omaha in 1950. But was he happy? Some say no.” What I end up with is “John Q Doe was born inOmahain 1950. But was hehappy? Some say no.” So,  I somehow need to preserve a single space around the app elements. I can’t <code>preserve-space()</code> because I use extra whitespace for readability, and I can’t simply use <code>&lt;xsl:text&gt;</code> to insert spaces on the template match for <code>tei:app</code>, because sometimes punctuation comes immediately after the <code>&lt;app&gt;</code> element, as does the question mark above. I’m stumped.</p>