[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Question about template priority
I'm a little perplexed by a transform I have. Basically the input file looks like: <ns:foo /> The transform file looks like: <!--(1)--><xsl:template match="node()[generate-id(.) = generate-id(root(.)/*[1])]" /> <!--(2)--><xsl:template match="ns:foo" /> <!--(3)--><xsl:template match="/"> <xsl:apply-templates select="*[1]" /> </xsl:template> What template (1) is suppose to do is catch document elements that are not ns:foo, e.g., someone gave the wrong XML document to the transform. However, template (1) is always invoked regardless of whether the correct XML input document is given or not. Looking at Michael Kay's book, it says that priority of a template is based on: 1. select all templates that have a match attribute; selected templates (1,2,3) 2. select all templates that have the same mode as the apply-template; selected templates (1,2,3) 3. select all templates whose pattern matches the node; selected templates (1,2) 4. select the one with the highest import precedence; selected templates (1,2) 5. select the one with the highest priority; selected templates (?) Neither template (1 or 2) have a priority so in order to determine the template with the highest priority it depends upon the match pattern syntax: 1. Pattern1 | Pattern2 = treat Pattern1 and Pattern2 separately and determine their default priority 2. QName, @QName, child::QName, attribute::QName, processing-instruction, (literal) = 0.0 priority 3. NCName:*, @NCName:*, child::NCName:*, attribute::NCName:* = -0.25 priority 4. NodeTest, @NodeTest, child::NodeTest, attribute::NodeTest = -0.5 priority 5. otherwise = 0.5 priority Template (2) looks to me to be a QName and should therefore get a 0.0 priority. Template (1) looks to me to be a NodeTest and should therefore get a -0.5 priority. However, when I run Saxon 9.1.0.7J, it always selects template (1). So I added a priority="0" to template (1) and Saxon gives me XTRE0504 ambigious rule match indicating that template (2) priority is in fact zero. Changing the priority for template (1) to -0.1 and template (2) is executed which indicates that Saxon thought that the default priority pattern for template (1) was "otherwise" and selected 0.5 for the priority which is why it was executed without a priority attribute. So why isn't template (1) considered a NodeTest? When I lookup NodeTest in Michael Kay's book in the examples it clearly shows: node() This *NodeTest* selects all nodes on the relevant axis. Inquiring minds would like to know, Andy.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|