title: removing invalid characters in xml with xslt
body: <p>In an XML-file I am seeing this in the source: 
  <code>&amp;lt;#&amp;gt;</code> which causes problems in another application which sees this as &lt;#&gt;</p>
  
  <p>I am using XSLT2.0 and I have tried to do a replace on anything from # to div to remove the <code>&amp;lt;#&amp;gt;</code> with an empty string altogether. 
  I have done this by putting the structure inside a variable and replacing.</p>
  
  <p>The result of the replace function is that I am loosing all other elements as well.
  Any suggestions are welcome. 
  The input could look something like this:</p>
  
  <pre><code>`&lt;html&gt;
   &lt;body&gt;
     &lt;p&gt;&amp;lt;#&amp;gt;This is just a test&lt;/p&gt;
   &lt;/body&gt;
  &lt;/html&gt;`
  </code></pre>
  
  <p>But it can also look something like this:</p>
  
  <pre><code>`&lt;html&gt;
   &lt;body&gt;
     &amp;lt;#&amp;gt;&lt;p&gt;This is just a test&lt;/p&gt;
   &lt;/body&gt;
  &lt;/html&gt;`
  </code></pre>
  
  <p>Wanted out put is:</p>
  
  <pre><code>`&lt;html&gt;
   &lt;body&gt;
     &lt;p&gt;This is just a test&lt;/p&gt;
   &lt;/body&gt;
  &lt;/html&gt;`
  </code></pre>
  
  <p>The XSL I have tried is this, which removes all elements. I do see I am doing this on a copy-of, so that' might be wrong...:</p>
  
  <pre><code>`&lt;xsl:template name="body"&gt;
    &lt;xsl:copy-of select="replace($bodycontent, '#', 'div /')" /&gt;
   &lt;/xsl:template name="body"&gt;
  
     &lt;xsl:variable name="bodycontent"&gt;
      &lt;xsl:apply-templates select="/newsMessage/itemSet/newsItem/contentSet/inlineXML/h:html/h:body/h:section/h:p" /&gt;
      &lt;p class="txt-ind"&gt;
          &lt;xsl:value-of select="//rightsInfo/copyrightHolder/name" /&gt;
      &lt;/p&gt;
  &lt;/xsl:variable&gt;`
  </code></pre>