CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Jun 2002
    Posts
    137

    Question 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.


  2. #2
    Join Date
    May 2002
    Location
    Manchester, UK
    Posts
    105
    Neither as the XSL file is invalid because you have two templates with an identical match value.

  3. #3
    Join Date
    Aug 2001
    Location
    Russia, Moscow
    Posts
    26
    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.

  4. #4
    Join Date
    Jun 2002
    Posts
    137
    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
  •  





Click Here to Expand Forum to Full Width

Featured