<xsl:for-each select="//cd/*[not(self::price or self::year)]">
But actually this is bad and unnecessarily complicated. Better:
<xsl:template match="catalog">
<html>
<body>
<xsl:apply-templates select="cd/*" />
</body>
</html>
</xsl:template>
<!-- this is an empty template to mute any unwanted elements -->
<xsl:template match="cd/price | cd/year" />
<!-- this is to output wanted elements -->
<xsl:template match="cd/*">
<xsl:text>Current node: </xsl:text>
<xsl:value-of select="."/>
<br />
</xsl:template>
Avoid <xsl:for-each>
. Almost all of the time it is the wrong tool and should be substituted by <xsl:apply-templates>
and <xsl:template>
.
The above works because of match expression specificity. match="cd/price | cd/year"
is more specific than match="cd/*"
, so it is the preferred template for cd/price
or cd/year
elements. Don't try to exclude nodes, let them come and handle them by discarding them.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…