XSL template priorities: Which comes first, priority or predicates?

Discussion in 'XML' started by Soren Kuula, Apr 13, 2005.

  1. Soren Kuula

    Soren Kuula Guest

    Hi,

    Suppose I have:

    <xsl:template match="foo[position()!=last()]"/>
    <xsl:template match="foo[position()=last()]"/>

    -- is that an error (same priority)? (my precessor reports nothing, buts
    as far as I recall it doesn't really have to). Or is the priority a
    post-predicate-survival issue?

    Are these any better or worse (with respect to specification
    fulfillment) that the above pair?

    <xsl:template match="foo[position() &gt; 2]"/>
    <xsl:template match="foo[position() &lt; 4]"/>

    (yes I could find out for myself all right .. and who knows if I will be
    the first onw ansering myself :) But isn't an interesting little gotcha?)

    Soren
     
    Soren Kuula, Apr 13, 2005
    #1
    1. Advertising

  2. Soren Kuula <dongfang-remove_this@remove_this-bitplanet.net> writes:

    > Hi,
    >
    > Suppose I have:
    >
    > <xsl:template match="foo[position()!=last()]"/>
    > <xsl:template match="foo[position()=last()]"/>
    >
    > -- is that an error (same priority)?


    These two match patterns match distinct nodes so that is no more an
    error than match="a" and match="b".

    > (my precessor reports nothing, buts
    > as far as I recall it doesn't really have to). Or is the priority a
    > post-predicate-survival issue?
    >
    > Are these any better or worse (with respect to specification
    > fulfillment) that the above pair?
    >
    > <xsl:template match="foo[position() &gt; 2]"/>
    > <xsl:template match="foo[position() &lt; 4]"/>


    here for position()=3 both templates match, with the same priority, so
    this is an error, butit is specified as being recoverable with the
    recovery action, if the processor does not report the error, is to take
    the last one on the stylesheet. (This is the only case in which order of
    the templates makes any difference.)

    with saxon for example with -w0 no error is generated, with the default
    -w1 a warning is made but the last template is used, with -w2 it is
    taken as a fatal error.

    > (yes I could find out for myself all right .. and who knows if I will be
    > the first onw ansering myself :) But isn't an interesting little gotcha?)
    >
    > Soren


    David
     
    David Carlisle, Apr 13, 2005
    #2
    1. Advertising

  3. Soren Kuula (dongfang-remove_this@remove_this-bitplanet.net) wrote:
    : Hi,

    : Suppose I have:

    : <xsl:template match="foo[position()!=last()]"/>
    : <xsl:template match="foo[position()=last()]"/>

    : -- is that an error (same priority)? (my precessor reports nothing, buts
    : as far as I recall it doesn't really have to). Or is the priority a
    : post-predicate-survival issue?

    xslt 1.0 sect 5.5

    The processor _may_ signal an error if they both match and have the same
    priority.

    It doesn't have to signal an error, but in that case it _must_ choose the
    match nearest the end of the style sheet (ie. the one that occurs last).

    Is that what you mean by post-predicate-survival issue? If so then then
    the answer is "yes".

    In anycase, the only question is whether a processor will accept it at
    all. Some obviously will, some might not, but if they do then the choice
    of which template to use is unambiguous.

    (I have nothing to say about your other question.)


    --

    This space not for rent.
     
    Malcolm Dew-Jones, Apr 13, 2005
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jason Sachs

    which comes first?

    Jason Sachs, Feb 15, 2007, in forum: C++
    Replies:
    2
    Views:
    330
    Dave Rahardja
    Feb 16, 2007
  2. Replies:
    7
    Views:
    574
  3. Jack Dowson

    Chick and egg,which comes first?

    Jack Dowson, Sep 16, 2007, in forum: Java
    Replies:
    18
    Views:
    601
  4. Nathan Sokalski
    Replies:
    4
    Views:
    624
    PJ on Development
    Nov 8, 2007
  5. Marcel Müller
    Replies:
    3
    Views:
    594
    Marcel Müller
    Apr 27, 2009
Loading...

Share This Page