Click to See Complete Forum and Search --> : A newbie's question on xsl:template match=""


sandodo
July 9th, 2002, 05:05 AM
For example
<xsl:template match = "MATCHTAG">
<!-- do something here -->
</xsl:template>
<xsl:template match = "MATCHTAG">
<!-- do something else here -->
</xsl:template>

which match will be used? Sometimes it is not so obvious that user does use the same match condition. Is there any method
to prevent such error-prone cases.

:)

Simon Wilkins
July 12th, 2002, 06:23 AM
Neither as the XSL file is invalid because you have two templates with an identical match value.

dkar
July 16th, 2002, 05:42 AM
This sample is valid. And the last matching template with the same priority will work.

There are three ways to avoid this ambiguity.

1. to make more sophisticated match
<xsl:template match = "NNN[@AAA='15']">
<!-- do something here -->
</xsl:template>
<xsl:template match = "NNN[@AAA!='15']">
<!-- do something else here -->
</xsl:template>

2. to use explicitly "priority" (from -9 to 9)

<xsl:template match = "NNN[@AAA='15']" priority="7">
<!-- do something here -->
</xsl:template>
<xsl:template match = "*" priority="-4">
<!-- do default -->
</xsl:template>

3. to use "mode"
<xsl:apply-templates select='*' mode="myMode1"/>
.......
<xsl:template match = "NNN" mode="myMode1">
<!-- do something here -->
</xsl:template>
<xsl:template match = "*" mode="myMode2">
<!-- do default -->
</xsl:template>

sandodo
July 16th, 2002, 09:52 PM
Hi, thanks a lot for your replies. But you know, sometimes it is just needed to do such matching in order to achieve some purposes. :( and sometimes it is also hard to differentiate them with attribute. :(