|
-
July 9th, 2002, 05:05 AM
#1
A newbie's question on xsl:template match=""
For example
Code:
<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.
-
July 12th, 2002, 06:23 AM
#2
Neither as the XSL file is invalid because you have two templates with an identical match value.
-
July 16th, 2002, 05:42 AM
#3
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>
Denis.
-
July 16th, 2002, 09:52 PM
#4
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|