'Can we just keep particular tags inside a parent tag and delete all other tags in xslt1.0?

Let's say i have data like below:

<caption>
 <p> some data </p>
 <b> bold data </b>
 <i> italic data </i>
 <a href=""> link data </a> 
 <u> underline data </u>
 <ul>
   <li>ul list data</li>
 </ul>  
 <ol>
   <li>ol list data</li>
 </ol>
</caption>

I want output as:

<caption>
 some data 
 <b> bold data </b>
 <i> italic data </i>
 <a href=""> link data </a> 
 <u> underline data </u>
  ul list data
  ol list data
</caption>

I want to delete all tags inside caption tag except bold italic underine and anchor tag. Thanks in advance.



Solution 1:[1]

Use the identity template where you want to retain the tags:

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

and a variant that drops the tags in other cases:

<xsl:template match="p|ul|ol|li">
  <xsl:apply-templates/>
</xsl:template>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Michael Kay