I want to remove all tags from my XML file except a finite number of tags, which i am aware of . How can i do that with XSLT.
I know i can use the following to strip div tags from my xml but i want to negate, like Strip all BUT Div.
<xsl:template match = "div">
<xsl:apply-templates select="@*|node()"/>
</xsl:template>
More Snippet of the XSLT file:
<xsl:template match="div"> <!-- switch the element name -->
<xsl:element name="newdiv">
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:element>
</xsl:template>
<xsl:template match="div"/>
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
I believe this question was answered already.
Use two templates.
Fourth edit.
Input sample:
XSLT transformation to do what you need:
This REMOVES ALL TAGS EXCEPT DIV. And KEEPS ALL TAG CONTENT. I just tried it.