Here\'s the sample data:
Empire Burlesque
Bob Dylan
I'd start experimenting with something like
"//cd/*[(name() != 'price') and (name() != 'year')]"
Or you just do normal recursive template matching with <xsl:apply-templates/>
, and then have empty templates for <price/>
and <year/>
elements:
<xsl:template match="price"/>
<xsl:template match="year"/>
<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.