XSLT does not match specific attributes

Is it possible to map attributes that do not belong to a subset of attributes? For example, I would like to combine everything except @ attr1 and @ attr2. Is there a way to write a pattern matching operator similar to the following, or am I mistaken about this?

<xsl:template match="NOT(@attr1) and NOT(@attr2)"> 

thank

+5
xpath xslt
Jul 16 '09 at 11:59
source share
2 answers

The easiest way is to use two templates:

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

The first template will catch links to the ones you want to ignore, and just eat them. The second will match the remaining attributes.

+7
Jul 16 '09 at 12:06
source share

What is a request op. 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 it is missing when performing a single copy operation. Another answer does not work in this situation. eg.

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



All Articles