[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Confused with templates and XPath


Subject: Re: [xsl] Confused with templates and XPath
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 8 Jan 2004 11:29:01 GMT

> Doesnt the //para apply to any para in the document?

yes a match of "//para" is exactly the same as a match of "para" and
will match every para element.

Normally we tell people that starting a match with // does nothing
useful, but does no harm either, but in this case it does do harm.

If the stylesheet had

<xsl:template match="para">
<xsl:template match="chapter/para">

Then both templates would match para children of chapter.
XSLT never applies too templates and if two match it uses the one of
highest priority. As neither of these templates has a priority attribute
the default priorities will be used, and the default priority for a
match involving a "/" step is higher than that of a match with just a
single element name, so the first template will be used if teh para is
_not_ a child of chapter and the second will be used if it is.

However in your case


<xsl:template match="//para">
<xsl:template match="chapter/para">

both templates have the same priority, this is an error and the system
could just fail and produce no output, but it is allowed to recover
from the error and use the last specified template, in which case
it will act as above, if they are really specified in this order.

You should report that as a bug to the author of the stylesheet, relying
on a system's silent error recovery is bad practice.

David


-- 
http://www.dcarlisle.demon.co.uk/matthew

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



Current Thread
Keywords