tags:

views:

72

answers:

2

Hey,

I am debugging the xsl stylesheet of someone else and I noticed a lot of template matches aimed at hiding certain content.

Ex: <tag hide="X">

So their rules go something like this.

<xsl:template match="tag1[@hide='x']" />
<xsl:template match="tag2[@hide='x']" />
<xsl:template match="tag3[@hide='x']" />

There seems to be a match for every possible tag that can appear in the document, which is around thirty or so. So my question is, is there a better way to do this in xsl than to have a list of template matches for the same attribute match?

+4  A: 

Try this:

<xsl:template match="*[@hide='x']" />
Andrew Hare
is there a difference between '*' and 'node()'?
jjnguy
Looks like it does the same thing.
maleki
No, they aren't. "*" is for element nodes exclusively, and "node()" matches any node type.
Tomalak
+1  A: 

In case you want to be more specific about what the template matches, you can do:

<xsl:template match="*[
  contains('|tag1|tag2|tag3|' , concat('|', name(), '|')) 
  and 
  @hide='x'
]" />
Tomalak
I like your alternate solution.
maleki