[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Preference rules for /something and /*

Subject: Re: Preference rules for /something and /*
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 18 Jun 2007 16:45:04 -0400
Re:  Preference rules for /something and /*
Abel,

At 04:07 PM 6/18/2007, you wrote:
I'm not sure if I get this right, so I'm asking here. If I have the following two rules:

<xsl:template match="/root" />
<xsl:template match="/*" />

I receive an "ambiguous rule match" error if the input matches the first. I figured, '*' is not very selective, so it should've conceived lowest priority (I know that a single '*' has prio -.5). What I'd guess is that I am having a compound rule here, similar to 'node/child' or 'node/*' which both receive prio +.5, with the parent node being the document node. Am I correct?

Yes. Both of these fall into the "anything else" category. There are three categories:


1. Simple tests by name, on the child or attribute axis in a single step
   e.g. "root" or "@root" -- priority 0
2. "Wildcard" matches on the child or attribute axis in a single step
   e.g. "@*" or "comment()" -- priority -0.5
3. Anything else
   e.g. "//root", "/root", "/*/root" or "/*" -- priority 0.5

(There's also a category between rules 1 and 2: a match on a namespace-and-type, with a single step, such as "html:*" or "svg:node()", gets priority 0.25.)

Or should a processor distinguish and select the first as having a higher prio (which intuitively seems more correct)?

Early drafts of XSLT attempted to specify such a cascade, but either it proved difficult to specify completely, or it appeared unlikely to work transparently enough, so the rules were simplified.


This does mean that you can get edge cases like yours, where matches using wildcards (node tests by type, that is, as opposed to those by name) fall into the "anything else" category by virtue of extra steps in the XPath.

Of course I can use priority='x', but I'm curious about the default prio here.

Given the rough granularity of the discriminations, it's generally wise to make priorities explicit as soon as there's any reasonable chance for confusion.


Cheers,
Wendell

PS: the same happens when I over-specify the first rule, i.e.: /root[foo[bar='y']]

Yes, that's also an "anything else".




======================================================================
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
======================================================================

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.