title: XSL Template-match replace element
body: <p>I have scoured the forums and and still not clear on this.  I'm very new to the topic.</p>
  
  <p>I have HTML output that is being sent to a browser email client (Outlook).  Outlook overwrites the characteristics of the <code>&lt;p&gt;</code> tag and introduces large spacing.</p>
  
  <p>I would like to set up a template-match to replace all <code>&lt;p&gt;</code> tags with <code>&lt;div&gt;</code> or <code>&lt;span&gt;</code>.</p>
  
  <p>For complicated reasons which will not be addressed in this post, I cannot stop the HTML from being rendered with <code>&lt;p&gt;</code> tags in it.</p>
  
  <p>So lets say that I have:</p>
  
  <pre><code>&lt;p xmlns="http://www.w3.org/1999/xhtml"&gt;
     &lt;span&gt;Some text&lt;/span&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>I would want the output to be</p>
  
  <pre><code>&lt;span&gt;Some text&lt;/span&gt;
  </code></pre>
  
  <p>with the <code>&lt;p&gt;</code> tags removed.</p>
  
  <p>If I have</p>
  
  <pre><code>&lt;p xmlns="http://www.w3.org/1999/xhtml"&gt;
    &lt;b&gt;Some other text&lt;/b&gt;
  &lt;/p&gt;
  </code></pre>
  
  <p>then I would be happy with either:</p>
  
  <pre><code>&lt;b&gt;Some other text&lt;/b&gt;
  </code></pre>
  
  <p>or</p>
  
  <pre><code>&lt;span&gt;
     &lt;b&gt;Some other text&lt;/b&gt;
  &lt;/span&gt;
  </code></pre>
  
  <p>Just as long as it gets rid of the <code>&lt;p&gt;</code> tags.</p>
  
  <p>It would also need to recognize <code>&lt;p&gt;</code> without any attributes.</p>
  
  <p>I thought about something like</p>
  
  <pre><code>&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;span&gt;
          &lt;xsl:apply-templates select="@*|node()" /&gt;
      &lt;/span&gt;
  &lt;/xsl:template&gt;
  </code></pre>
  
  <p>but this does not work.  The <code>&lt;p&gt;</code> tags still appear.</p>
  
  <p>It is possible to write an adapter which will intercept the HTML before it is sent to the smtp server and manipulate it, but there are considerable difficulties in this approach which I am looking to avoid.</p>
  
  <p>Is it even possible to do what I am attempting?  Any help greatly appreciated.</p>