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

S

Soren Kuula

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
 
D

David Carlisle

Soren Kuula said:
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
 
M

Malcolm Dew-Jones

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

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,840
Latest member
BrendanG78

Latest Threads

Top