title: Using xslt to remove specific html tags in string
body: <p>I have a string in my xml that contains html formatting tags. I would like to remove some, such as font family, but keep the paragraph breaks, and ideally bold and italic font styles.</p>
  
  <p>I have found several references to strip all html from strings and used sample code to do this. However I am left with a string that does not contain paragraph breaks which are important in my context, and moreover has nbsp characters in it. I have tried to create a variable to work further with the string but I got stuck here. </p>
  
  <p>This is what I get when stripping all html tags: </p>
  
  <pre><code>First test paragraph nisi deserunt. &amp;nbsp;Second test paragraph nisi ut aliquip ex ea commodo.&amp;nbsp; Third test paragraph dolor in reprehenderit in officia deserunt. &amp;nbsp;
  </code></pre>
  
  <p>This is what I would like to get:</p>
  
  <pre><code>First test paragraph nisi deserunt.
  
  Second test paragraph nisi ut aliquip ex ea commodo.
  
  Third test paragraph dolor in reprehenderit in officia deserunt
  </code></pre>
  
  <p>Is it possible to remove specific html tags from a string using xslt and leave others in place or to replace them to achieve something similar, it a string with desired html? I am writing in XSL version 1.0 and the processor is IE in an application. I am new to xslt and will be grateful for any help.</p>
  
  <p>This is my xslt:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
   &lt;xsl:stylesheet version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
  &lt;xsl:template match="/xml/exhibition"&gt;
  
  &lt;html&gt;
      &lt;head&gt;
      &lt;/head&gt;
      &lt;body&gt;      
  
  &lt;!--main structure--&gt;        
        &lt;xsl:for-each select="objects/object[string(subtheme)!='']"&gt; 
              &lt;xsl:sort select="subtheme"/&gt;
              &lt;xsl:variable name="cursection" select="string(subtheme)"/&gt;
  
              &lt;xsl:if test="count(preceding-sibling::node()[subtheme=$cursection])=0"&gt;
                  &lt;xsl:call-template name="output_by_section"&gt;
                      &lt;xsl:with-param name="parent" select="parent::node()"/&gt;
                      &lt;xsl:with-param name="field" select="$cursection"/&gt;
                  &lt;/xsl:call-template&gt;
              &lt;/xsl:if&gt;      
          &lt;/xsl:for-each&gt;     
      &lt;/body&gt;
  &lt;/html&gt;
  &lt;/xsl:template&gt;
  
  &lt;!--removes all html from string--&gt;
  &lt;xsl:template name="RemoveHtml"&gt;
    &lt;xsl:param name="String"/&gt;
    &lt;xsl:choose&gt;
      &lt;xsl:when test="contains($String, '&amp;lt;')"&gt;
        &lt;xsl:value-of select="substring-before($String, '&amp;lt;')"/&gt;
         &lt;xsl:call-template name="RemoveHtml"&gt;
          &lt;xsl:with-param name="String"
            select="normalize-space(substring-after($String, '&amp;gt;'))"/&gt;
        &lt;/xsl:call-template&gt;
      &lt;/xsl:when&gt;
      &lt;xsl:otherwise&gt;
        &lt;xsl:value-of select="normalize-space($String)"/&gt;
      &lt;/xsl:otherwise&gt;
    &lt;/xsl:choose&gt;
  &lt;/xsl:template&gt;
  
  &lt;!--template that provides main structure to my xslt--&gt;
  &lt;xsl:template name="output_by_section"&gt;
      &lt;xsl:param name="parent"/&gt;
      &lt;xsl:param name="field"/&gt;
  
      &lt;xsl:for-each select="$parent/object[subtheme=$field]"&gt; 
      &lt;div style="margin-bottom: 20px"&gt;
  
  &lt;!--calling template RemoveHtml--&gt;  
      &lt;xsl:variable name="stripped"&gt; 
      &lt;xsl:call-template name="RemoveHtml"&gt;
      &lt;xsl:with-param name="String" select="textentryhtml"/&gt;
      &lt;/xsl:call-template&gt;
      &lt;/xsl:variable&gt;
  &lt;!--attempting to add paragraph breaks--&gt;
      &lt;xsl:choose&gt;
          &lt;xsl:when test="contains($stripped, 'nbsp;')"&gt;
              &lt;p&gt;&lt;xsl:value-of select='substring-before($stripped, "nbsp;")'/&gt;&lt;/p&gt;
              &lt;p&gt;&lt;xsl:value-of select='substring-after($stripped, "nbsp;")'/&gt;&lt;/p&gt;
          &lt;/xsl:when&gt;
          &lt;xsl:otherwise&gt;
              &lt;xsl:value-of select="$stripped" /&gt;
          &lt;/xsl:otherwise&gt;
      &lt;/xsl:choose&gt;           
      &lt;/div&gt;
      &lt;div&gt;
          &lt;!--formatted text with full html for reference--&gt;  
          &lt;xsl:value-of select="textentryhtml" disable-output-escaping="yes" /&gt; 
      &lt;/div&gt;  
      &lt;/xsl:for-each&gt;
  
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>This is a sample of the relevant xml:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;xml&gt;
    &lt;exhibition&gt;
      &lt;objects&gt;
        &lt;object&gt;
          &lt;textentryhtml&gt;
            &amp;lt;SPAN style="FONT-FAMILY: 'ITCFranklinGothic LT Com Bk','sans-serif'; COLOR: black; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Arial; mso-fareast-language: EN-AU"&amp;gt;&amp;lt;FONT size=3&amp;gt;&amp;lt;SPAN style="FONT-FAMILY: 'ITCFranklinGothic LT Com Bk','sans-serif'; COLOR: black; FONT-SIZE: 12pt; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Arial; mso-fareast-language: EN-AU"&amp;gt;&amp;lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&amp;gt;&amp;lt;o:p&amp;gt;&amp;lt;SPAN style="FONT-FAMILY: 'ITCFranklinGothic LT Com Bk','sans-serif'; COLOR: black; FONT-SIZE: 12pt; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Arial; mso-fareast-language: EN-AU"&amp;gt;&amp;lt;SPAN style="FONT-FAMILY: 'ITCFranklinGothic LT Com Bk','sans-serif'; COLOR: black; FONT-SIZE: 12pt; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Arial; mso-fareast-language: EN-AU"&amp;gt;First test paragraph nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt.&amp;lt;/SPAN&amp;gt;
            &amp;lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&amp;gt;&amp;lt;SPAN style="FONT-FAMILY: 'ITCFranklinGothic LT Com Bk','sans-serif'; COLOR: black; FONT-SIZE: 12pt; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Arial; mso-fareast-language: EN-AU"&amp;gt;&amp;lt;o:p&amp;gt;&amp;amp;nbsp;&amp;lt;/o:p&amp;gt;&amp;lt;/SPAN&amp;gt;&amp;lt;/P&amp;gt;
            &amp;lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&amp;gt;&amp;lt;I style="mso-bidi-font-style: normal"&amp;gt;&amp;lt;SPAN style="COLOR: black; FONT-SIZE: 12pt; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Calibri; mso-fareast-language: EN-AU"&amp;gt;&amp;lt;FONT face=Calibri&amp;gt;Second test paragraph nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in. &amp;lt;o:p&amp;gt;&amp;lt;/o:p&amp;gt;&amp;lt;/FONT&amp;gt;&amp;lt;/SPAN&amp;gt;&amp;lt;/I&amp;gt;&amp;lt;/P&amp;gt;
            &amp;lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&amp;gt;&amp;lt;SPAN style="FONT-FAMILY: 'Times New Roman','serif'; COLOR: black; FONT-SIZE: 12pt; mso-fareast-font-family: 'Times New Roman'; mso-fareast-language: EN-AU"&amp;gt;&amp;lt;o:p&amp;gt;&amp;amp;nbsp;&amp;lt;/o:p&amp;gt;&amp;lt;/SPAN&amp;gt;&amp;lt;/P&amp;gt;
            &amp;lt;P style="MARGIN: 0cm 0cm 2.25pt" class=MsoNormal&amp;gt;&amp;lt;B style="mso-bidi-font-weight: normal"&amp;gt;&amp;lt;SPAN style="FONT-FAMILY: 'ITCFranklinGothic LT Com Bk','sans-serif'; COLOR: black; FONT-SIZE: 12pt; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Arial; mso-fareast-language: EN-AU"&amp;gt;Third test paragraph &amp;lt;/SPAN&amp;gt;&amp;lt;/B&amp;gt;&amp;lt;SPAN style="FONT-FAMILY: 'ITCFranklinGothic LT Com Bk','sans-serif'; COLOR: black; FONT-SIZE: 12pt; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Arial; mso-fareast-language: EN-AU"&amp;gt;nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in &amp;lt;/SPAN&amp;gt;&amp;lt;SPAN style="FONT-FAMILY: 'ITCFranklinGothic LT Com Bk','sans-serif'; COLOR: black; FONT-SIZE: 20pt; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Arial; mso-fareast-language: EN-AU"&amp;gt;voluptate velit esse cillum dolore&amp;lt;/SPAN&amp;gt;&amp;lt;SPAN style="FONT-FAMILY: 'ITCFranklinGothic LT Com Bk','sans-serif'; COLOR: black; FONT-SIZE: 12pt; mso-fareast-font-family: 'Times New Roman'; mso-bidi-font-family: Arial; mso-fareast-language: EN-AU"&amp;gt; eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt.&amp;lt;/SPAN&amp;gt;&amp;lt;/P&amp;gt;
            &amp;lt;P style="MARGIN: 0cm 0cm 0pt" class=MsoNormal&amp;gt;&amp;lt;/SPAN&amp;gt;&amp;lt;/o:p&amp;gt;&amp;lt;/SPAN&amp;gt;&amp;amp;nbsp;&amp;lt;/P&amp;gt;&amp;lt;/FONT&amp;gt;&amp;lt;/SPAN&amp;gt;
          &lt;/textentryhtml&gt;
        &lt;/object&gt;
      &lt;/objects&gt;
    &lt;/exhibition&gt;
  &lt;/xml&gt;
  
  &lt;/xsl:template&gt;
  &lt;/xsl:stylesheet&gt;
  </code></pre>