Previous | Next | Indexes
adultinternetusers > Tutorials > XSLT 2.0 Tutorial > Templates - basic usage (11/12) >

Implicit priorities

While it is common to have several matching templates for a single source node, many stylesheets does not contain explicit priority assignment. If priority of a template is not given it is automatically calculated based on match attribute.

While there are several rules for assignment of priority and numbers are given for them, it is sufficient to remember that templates with names explicitly given have precedence over "*" and that templates with matchContaining only name of the element are of lower precedence than templates containing further information about the element to be matched.

If there are two matching templates of the same priority the processor may announce an error and stop processing. The standard also permits the processor to resolve the conflict by using the template which occurs last in the stylesheet. Processors using the second possibility usually issue a warning in this case.

XSLT

      <xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"
                        omit-xml-declaration="yes"/>

            <xsl:template  match="/">
                  <xsl:apply-templates  select="aaa"/>
            </xsl:template>

            <xsl:template  match="aaa">
                  <xxx>
                        <xsl:apply-templates  select="*"/>
                  </xxx>
            </xsl:template>

            <xsl:template  match="*">
                  <p1>
                        <xsl:value-of  select="."/>
                  </p1>
            </xsl:template>

            <xsl:template  match="bbb">
                  <p22>
                        <xsl:value-of  select="."/>
                  </p22>
            </xsl:template>

            <xsl:template  match="bbb[2]">
                  <p333>
                        <xsl:value-of  select="."/>
                  </p333>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>
            <bbb>B1</bbb>
            <bbb>B2</bbb>
            <ccc>C</ccc>
            <ddd>D</ddd>
      </aaa>
Output

      <xxx>
            <p22>B1</p22>
            <p333>B2</p333>
            <p1>C</p1>
            <p1>D</p1>
      </xxx>


Previous chapter: - - -
Next chapter: Sequences
Previous page: Template priorities
Next page: Applying templates with lower priority - xsl:next-match

Kevin Carr in Stanton

Natural Skin Care and European Soaps
Kevin Carr
Mayor Dave Shawver Stanton
Internetusers


You can also get Organic Skin Care products from Bliss Bath Body and you must check out their Natural Body Lotions and bath soaps

Now if you are looking for the best deals on surf clothing from Quiksilver and Roxy then you have to check these amazing deals here:

Hey, check out this Organic Skin Care European Soaps along with Natural Lavender Body Lotion and shea butter

and we can get surf t shirts surfing shirt and And you must check out this website swim suit swimming suit and swim trunks