Re: [xsl] apply-templates and priorities

Subject: Re: [xsl] apply-templates and priorities
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 15 Sep 2004 18:19:48 -0400
Simon,

Actually, "*" doesn't match the same node as "/". "*" matches any element node (that is a child of something, which all elements are). "/" matches the root node (which is not an element).

This explains your result, because the template matching "/" is always fired first, and it contains no xsl:apply-templates instruction, so node is selected for processing, so the other template never gets matched.

The priorities are a red herring here. Match them both to "/" and you'll see what you expect.

Cheers,
Wendell

At 05:55 PM 9/15/2004, you wrote:
I'm confused about how the priorities of templates are computed.  Using
saxon 8.0, this stylesheet:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:template match="*" priority="1">
<xsl:message>in first</xsl:message>
</xsl:template>


    <xsl:template match="/" priority="10">
        <xsl:message>in second</xsl:message>
    </xsl:template>
</xsl:stylesheet>

and an arbitrary source doc produces the message "in second" (as expected).

Now if I switch around the priorities:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">
<xsl:template match="*" priority="10">
<xsl:message>in first</xsl:message>
</xsl:template>


    <xsl:template match="/" priority="1">
        <xsl:message>in second</xsl:message>
    </xsl:template>
</xsl:stylesheet>

Then I still get "in second" (NOT as expected).  Note that if the
patterns are the same then this behaviour goes away (the latter
case produces "in first").  Also, I see the same behaviour in earlier
versions of saxon.

My understanding of these things is that the default priorities for the
two templates are different (as per section 5.5 of the 1.0 spec), but
that the explicit priority just overrides the default priorities.  Is
something else going on, or have I missed something really simple?


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


--+------------------------------------------------------------------ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/ or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx> --+--

Current Thread