title: Collapsing nodes if no other element is inbetween
body: <p>I have this xml file:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
  &lt;doclist&gt;
  &lt;text attribute="a"&gt;This is a &lt;tag1&gt;sentence&lt;/tag1&gt; &lt;tag1&gt;with&lt;/tag1&gt; a few            
  &lt;tag1&gt;words&lt;/tag1&gt;.&lt;/text&gt;
  &lt;-- many more text nodes with none, one or several '&lt;tag1&gt;' in it --&gt;
  &lt;/doclist&gt;
  </code></pre>
  
  <p>and i want to get this result:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
  &lt;doclist&gt;
  &lt;text attribute="a"&gt;This is a &lt;tag1&gt;sentence with&lt;/tag1&gt; a few &lt;tag1&gt;words&lt;/tag1&gt;. 
  &lt;/text&gt;
  &lt;-- many more text nodes with none, one or several '&lt;tag1&gt;'s in it --&gt;
  &lt;/doclist&gt;
  </code></pre>
  
  <p>I have tried doing it with a regex:</p>
  
  <pre><code>&lt;xsl:template match="text"&gt;
  &lt;text&gt;
  &lt;xsl:apply-templates select="@*"/&gt; &lt;!-- templ. to copy attributes of text --&gt;
  &lt;xsl:analyze-string select="." 
  regex="&amp;lt;tag1&gt;(.+)&amp;lt;tag1&gt;&amp;lt;tag1&gt;(.+)&amp;lt;/tag1&gt;"&gt;
  &lt;!-- also tried . instead of &amp;lt; --&gt;
  &lt;xsl:matching-substring&gt;
  &lt;xsl:for-each select="."&gt;
  &lt;tag1&gt;
  &lt;xsl:value-of-select="regex-group(1)"&gt;
  &lt;xsl:text&gt; &lt;xsl:text&gt;
  &lt;xsl:value-of-select="regex-group(2)"&gt;
  &lt;/tag1&gt;
  &lt;/xsl:matching-substring&gt;
  &lt;xsl:non-matching-substring&gt;
  &lt;xsl:for each select="."&gt;
  &lt;xsl:value-of select="."/&gt;
  &lt;/xsl:for-each&gt;
  &lt;/xsl:non-matching-substring&gt;
  &lt;/xsl:analyze-string&gt;
  &lt;/text&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>But my output looks like this:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="iso-8859-1"?&gt;
  &lt;doclist&gt;
  &lt;text attribute="a&gt;This is a sentencewitha few words. 
  &lt;/text&gt;
  &lt;-- many more text nodes with none, one or several '&lt;tag1&gt;'s in it --&gt;
  &lt;/doclist&gt;
  </code></pre>
  
  <p>My guess, what happens is that the matches arent found, as no<code>&lt;tag1&gt;</code>s appears in the result - but i dont understand why only the words surounded by the tag lose their whitespace... 
  How can i correctly collapse <code>&lt;tag1&gt;</code>s that are direct neighbours?</p>