XSLT do not match certain attributes

The easiest way would be to use two templates:

<xsl:template match="@attr1|@attr2"/>
<xsl:template match="@*">
    ....
</xsl:template>

The first template will catch the references to those you want to ignore, and simply eat them. The second will match the remaining attributes.


The original inquiry is possible. Use the following:

<xsl:template match="@*[local-name()!='attr1' and local-name()!='attr2']">
    ....
</xsl:template>

This is especially useful if you want to change an attribute or add it if missing withing a single copy operation. The other answer does not work in such situation. e.g.

  ...
  <xsl:copy>
     <xsl:attribute name="attr1">
        <xsl:value-of select="'foo'"/>
     </xsl:attribute>
     <xsl:apply-templates select="@*[local-name()!='attr1']|node()"/>
  </xsl:copy>
  ...

Tags:

Xpath

Xslt