Exclude attribute from a specific xml element using xslt
inside the select, you can exclude (or include,) the attribute, using the name function.
For example, <xsl:copy-of select="@*[name(.)!='theAtribute']|node()" />
What is not working? Do you want the same content, just without the @theAtribute
?
If so, make sure your stylesheet has the empty template for @theAtribute
, but also has an identity template that copies everything else into the output:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--empty template suppresses this attribute-->
<xsl:template match="@theAtribute" />
<!--identity template copies everything forward by default-->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
If you only want to suppress certain @theAtribute
, then you can make the match criteria more specific. For instance, if you only wanted to remove that attribute from the div
who's @id="qaz"
, then you could use this template:
<xsl:template match="@theAtribute[../@id='qaz']" />
or this template:
<xsl:template match="*[@id='qaz']/@theAtribute" />
If you want to remove @theAttribute
from all div
elements, then change the match expression to:
<xsl:template match="div/@theAtribute" />