title: XSLT - search and find specific tag
body: <p>Is it possible in XSLT to find a specific tag and replace it with its contents? For example, given this XML:</p>
  
  <pre><code>&lt;span&gt;Hello world&lt;/span&gt;
  </code></pre>
  
  <p>we'd end up with this:</p>
  
  <pre><code>Hello world
  </code></pre>
  
  <p>So the useless and redundant SPAN tag is replaced with its contents, at any level (recursively). We'd want to find the "naked" span tags (the ones with no attributes) and replace them with their content. </p>
  
  <p>I'm processing XML over which I don't have control. Thanks.</p>
  
  <p>Update: Here's what the *.XSL file contains, followed by sample output:</p>
  
  <pre><code>&lt;xsl:stylesheet 
    version="1.0" 
    exclude-result-prefixes="x d xsl msxsl cmswrt"
    xmlns:x="http://www.w3.org/2001/XMLSchema" 
    xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" 
    xmlns:cmswrt="http://schemas.microsoft.com/WebParts/v3/Publishing/runtime"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt"&gt;
    &lt;xsl:param name="ItemsHaveStreams"&gt;
      &lt;xsl:value-of select="'False'" /&gt;
    &lt;/xsl:param&gt;
    &lt;xsl:variable name="OnClickTargetAttribute" select="string('javascript:this.target=&amp;quot;_blank&amp;quot;')" /&gt;
    &lt;xsl:variable name="ImageWidth" /&gt;
    &lt;xsl:variable name="ImageHeight" /&gt;
    &lt;xsl:template name="Contact" match="Row[@Style='Contact']" mode="itemstyle"&gt;
        &lt;div class="outer-container"&gt;
        &lt;table border="0" cellspacing="0" width="100%"&gt;
          &lt;tr&gt;
            &lt;td class="ms-vb" style="text-align:left; padding:9px;"&gt;
              &lt;span style="font-weight:bold; border-bottom:1px solid #999;"&gt;&lt;xsl:value-of select="@Title"/&gt;&lt;/span&gt;
  
              &lt;!-- Phone and Emergency Phone --&gt;
              &lt;xsl:if test="@Phone != '' or @EmergencyPhone != ''"&gt;
                &lt;xsl:if test="@Phone != ''"&gt;
                  &lt;xsl:value-of select="@Phone" disable-output-escaping="yes"/&gt;&lt;br /&gt;
                &lt;/xsl:if&gt;
                &lt;xsl:if test="@EmergencyPhone != ''"&gt;
                  &lt;xsl:value-of select="@EmergencyPhone" disable-output-escaping="yes"/&gt;
                &lt;/xsl:if&gt;
              &lt;/xsl:if&gt;
  
              &lt;!-- Email --&gt;
              &lt;xsl:if test="@Email != ''"&gt;
                &lt;span style="text-align:left"&gt;E-mail: &lt;a href="mailto:{@Email}"&gt;&lt;xsl:value-of select="@Email"/&gt;&lt;/a&gt;&lt;/span&gt;
              &lt;/xsl:if&gt;
  
              &lt;!-- Address &amp; Map --&gt;
              &lt;!--
                Must test for both empty string and empty div tags, escaped.
              --&gt;
              &lt;xsl:if test="@Address != '' and @Address !='&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;'"&gt;
                &lt;p&gt;Address: &lt;xsl:value-of select="@Address" disable-output-escaping="yes"/&gt;&lt;/p&gt;
              &lt;/xsl:if&gt;
              &lt;xsl:if test="@Map != ''"&gt;
                (&lt;a href="{@Map}"&gt;MAP&lt;/a&gt;)
              &lt;/xsl:if&gt;
  
              &lt;!-- Opening Hours --&gt;
              &lt;xsl:if test="@OpeningHours != ''"&gt;
                &lt;p&gt;&lt;b&gt;Opening Hours:&lt;/b&gt;&lt;/p&gt;
                &lt;xsl:value-of select="@OpeningHours" disable-output-escaping="yes"/&gt;
              &lt;/xsl:if&gt;
            &lt;/td&gt;                 
          &lt;/tr&gt;
        &lt;/table&gt; 
        &lt;/div&gt; 
    &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>Here's a sample output currently:</p>
  
  <pre><code>Contact Health Services
  
      962-8328
      962-8945 
  
  Emergency only: 962-8884
  After hours, contact Security Dispatch to connect with Health Services staff on duty.
  
  E-mail: health@mydomain.org
  
  Address: 
  123 Main St.
  
  (MAP)
  
  Opening Hours:
  Sunday -Thursday     08:00 -17:30
  </code></pre>