title: Merge all values of a node's child nodes
body: <p>I'm completely new to XSLT. In a large text corpus, I should merge all values of a node's child nodes:</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
      &lt;Informations&gt;
          &lt;Information lang="de" type="a"&gt;
              &lt;title&gt;Product&lt;/title&gt;
              &lt;Holder&gt;Big Company&lt;/Holder&gt;
              &lt;Code&gt;0101010&lt;/Code&gt;
              &lt;content&gt;
                  &lt;div&gt;
                      &lt;p class="s4" id="section1"&gt;
                          &lt;span class="s2"&gt;
                              &lt;span&gt;This is Text&lt;/span&gt;
                          &lt;/span&gt;
                          &lt;sup class="s3"&gt;
                              &lt;span&gt;®&lt;/span&gt;
                          &lt;/sup&gt;
                      &lt;/p&gt;
                      &lt;p class="s6"&gt;
                          &lt;span class="s5"&gt;
                              &lt;span&gt;Sometimes sentences ar&lt;/span&gt;
                          &lt;/span&gt;
                          &lt;span class="s5"&gt;
                              &lt;span&gt;e split by tags&lt;/span&gt;
                          &lt;/span&gt;
                      &lt;/p&gt;
                   &lt;/div&gt;
               &lt;/content&gt;
           &lt;/Information&gt;
      &lt;Informations&gt;
  </code></pre>
  
  <p>The resulting document should look like</p>
  
  <pre><code>&lt;?xml version='1.0' encoding='UTF-8'?&gt;
      &lt;Informations&gt;
          &lt;Information lang="de" type="a"&gt;
              &lt;title&gt;Product&lt;/title&gt;
              &lt;Holder&gt;Big Company&lt;/Holder&gt;
              &lt;Code&gt;0101010&lt;/Code&gt;
              &lt;content&gt;
                  &lt;div&gt;
                      &lt;p&gt;This is Text®&lt;/p&gt;
                      &lt;p&gt;Sometimes sentences are split by tags&lt;/p&gt;
                  &lt;/div&gt;
              &lt;/content&gt;
          &lt;/Information&gt;
      &lt;Informations&gt;          
  </code></pre>
  
  <p>So basically, I have to copy the whole structure but merge all values of the p-tags' subnodes while getting rid of these subnodes. I'd be very greatful for some help. Thanks!</p>
  
  <p><strong>Update</strong>: Without preserving the whitespaces within the p nodes to be stripped, some words become directly conjoined to each other. E.g. in an environment such as in</p>
  
  <pre><code>        &lt;p class="s8"&gt;
             &lt;span class="s9"&gt;
                &lt;span&gt;Inform your &lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s9"&gt;
                &lt;span&gt;dentist.&lt;/span&gt;
             &lt;/span&gt;
          &lt;/p&gt;
  </code></pre>
  
  <p>the resulting text is: Inform yourdentist
  Therefore I tried to preserve the trailing whitespaces in the style sheet:</p>
  
  <p>
  </p>
  
  <pre><code>&lt;xsl:strip-space elements="*"/&gt;
  &lt;xsl:preserve-space elements="p"/&gt;
  &lt;xsl:output indent="yes" method="xml" encoding="utf-8" omit-xml-declaration="no"/&gt;
  &lt;xsl:template match="@*|node()"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:apply-templates select="@*|node()"/&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  
  &lt;xsl:template match="p"&gt;
      &lt;xsl:copy&gt;
          &lt;xsl:value-of select='normalize-space()'/&gt;
      &lt;/xsl:copy&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p></p>
  
  <p>However, words split in two span tags are not correctly conjoined now. E.g from the example above: "sentences ar e split". I tried to find a way to mask/convert all trailing whitespaces first, but it didn't work out..</p>
  
  <p><strong>Update 2</strong>: The wrong results arise from sections such as the following where empty tags (resp. containing a whitespace only) separate two words. Is there a possibility not to process them as empty tags?</p>
  
  <pre><code>        &lt;p class="s3"&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt;Read&lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt; &lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt;the&lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt; information &lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt;sheet&lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt; &lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt;carefully&lt;/span&gt;
             &lt;/span&gt;
          &lt;/p&gt;
  </code></pre>
  
  <p><strong>Update 3</strong>: With the 2-step-transformation almost everythings works except for the fact that the  tags are ignored, so that</p>
  
  <pre><code>        &lt;p class="s3"&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt;Read&lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt; &lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt;the&lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt; information &lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt;sheet&lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt; &lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s4"&gt;
                &lt;span&gt;carefully&lt;/span&gt;
             &lt;/span&gt;
             &lt;span class="s4"&gt;
                &lt;/br&gt;
             &lt;/span&gt;
             &lt;span class="s3"&gt;
                &lt;span&gt;This is important&lt;/span&gt;
          &lt;/p&gt;
  </code></pre>
  
  <p>Becomes "Read the information sheet carefullyThis is important." I tried to convert every /br to a line break, but that doesn't work. Is it possible to somehow convert each /br into a closing /p-Tag and open a new p tag at the same time? Or converting it to</p>
  
  <pre><code>&lt;span&gt; &lt;/span&gt;
  </code></pre>
  
  <p>might work as well.</p>