White Lists :
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="*[not(self::description or self::p or self::i or self::em or self::strong or self::b or self::ol or self::ul or self::li or self::a)]"/> </xsl:stylesheet>
Please note that this removes unwanted elements and something below them. For example, to simply remove the font element but allow it to be child elements, change the last template as follows:
<xsl:template match="*[not(self::description or self::p or self::i or self::em or self::strong or self::b or self::ol or self::ul or self::li or self::a)]"/> <xsl:apply-templates/> </xsl:template>
Equivalent (and slightly cleaner) solution:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="@*|node()" priority="-3"> <xsl:copy/> </xsl:template> <xsl:template match="description|p|i|em|strong|b|ol|ul|li|a"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="*"/> </xsl:stylesheet>
The opposite approach is to blacklist unwanted elements:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template> <xsl:template match="font|span"/> </xsl:stylesheet>
Add apply-templates to the final template again if you want to allow children of missing elements.
source share