xsl-list
[Top] [All Lists]

[xsl] Difference in priority of node() and *

2008-02-15 10:03:29
I tested this stylesheet with Saxon 9.0.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                        version="2.0">

 <xsl:output method="text" />

 <xsl:template match="node()">
   1
   <xsl:apply-templates/>
 </xsl:template>

 <xsl:template match="*">
   2
   <xsl:apply-templates/>
 </xsl:template>

</xsl:stylesheet>

This is an arbitrary stylesheet, with no semantic significance. It
just studies the priority of template rules.

When this is run on a dummy XML (say, below):
<aaa>
 <bbb>123</bbb>
 <ccc>def</ccc>
</aaa>

I get output:

Recoverable error
  XTRE0540: Ambiguous rule match for /aaa
Matches both "node()" on line 7 of file:/E:/xml/xsleg/xslt/test.xsl
and "element()" on line 12 of file:/E:/xml/xsleg/xslt/test.xsl
Recoverable error on line 14 of file:/E:/xml/xsleg/xslt/test.xsl:
  XTRE0540: Ambiguous rule match for /aaa/bbb[1]
Matches both "node()" on line 7 of file:/E:/xml/xsleg/xslt/test.xsl
and "element()" on line 12 of file:/E:/xml/xsleg/xslt/test.xsl
Recoverable error on line 14 of file:/E:/xml/xsleg/xslt/test.xsl:
  XTRE0540: Ambiguous rule match for /aaa/ccc[1]
Matches both "node()" on line 7 of file:/E:/xml/xsleg/xslt/test.xsl
and "element()" on line 12 of file:/E:/xml/xsleg/xslt/test.xsl

[some more output]

I am curious, why these two templates rules are ambiguous. The XSLT
2.0 spec says, "In many cases this means that highly selective
patterns have higher priority than less selective patterns."

Isn't * more specific than node() ? I was hoping, that * would have
higher priority than node().

To solve this problem, I have to put priority attribute to one of the rules.

Can somebody please explain this ...


-- 
Regards,
Mukul Gandhi

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--