GNOME Bugzilla – Bug 56517
Template priorities wrong for patterns with alternatives
Last modified: 2009-08-15 18:40:50 UTC
I think my stylesheets are giving your libxslt a good exercise :) When a pattern has multiple subpatterns separated by '|', only the first subpattern has the correct priority. The following is a testcase: The document ============ <?xml version='1.0'?> <x> </x> The stylesheet ============== <?xml version='1.0'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'> <xsl:template match="/"> <root> <xsl:apply-templates /> </root> </xsl:template> <xsl:template match="x"> <xsl:text>Matched x template</xsl:text> <xsl:apply-templates /> </xsl:template> <!-- Case 1: y=0.0 /*=0.0, even though /* should be 0.5 --> <!-- works if split up to: <xsl:template match="/*"> or of course you reverse the order so the y pattern is screwed instead --> <xsl:template match="y|/*"> <xsl:text>Matched /* or y template</xsl:text> <xsl:apply-templates /> </xsl:template> <!-- Case 2: Here, both should have 5.0 priority but /* seems to have 0.0! <xsl:template match="y|/*" priority="5.0"> <xsl:text>Matched /* or y template</xsl:text> <xsl:apply-templates /> </xsl:template> --> </xsl:stylesheet> Output ====== For both cases: <?xml version="1.0"?> <root>Matched x template </root> It should match the last template instead. (Also see REC-XSLT, 5.5, If the pattern contains alternatives, "it is treated equivalently to a set of templates rules, one for each alternative.") libxml, libxslt version: the ones from CVS.
Okay thanks a lot for the report and the tests. I took the opportunity to clean this part a bit, fix 3 related bugs and improve the debugging output. I think this is now fixed: http://mail.gnome.org/archives/cvs-commits-list/2001-June/msg03754.html orchis:~/XSLT/tests/general -> xsltproc -v bug-39-.xsl ../docs/bug-39-.xml xsltParseStylesheetFile : parse bug-39-.xsl Added namespace: xsl mapped to http://www.w3.org/1999/XSL/Transform xsltPrecomputeStylesheet: removing ignorable blank node xsltParseStylesheetProcess : found stylesheet xsltCompilePattern : parsing '/' xsltCompilePattern : parsed /, default priority 0.500000 added pattern : '/' priority 0.500000 xsltCompilePattern : parsing 'x' xsltCompilePattern : parsed x, default priority 0.000000 added pattern : 'x' priority 0.000000 xsltCompilePattern : parsing 'y' xsltCompilePattern : parsed y, default priority 0.000000 xsltCompilePattern : parsing '/*' xsltCompilePattern : parsed /*, default priority 0.500000 added pattern : 'y' priority 0.000000 added pattern : '/*' priority 0.500000 parsed 3 templates Initializing keys on ../docs/bug-39-.xml Registering global variables Registering global variables from bug-39-.xsl xsltProcessOneNode: applying template '/' for / xsltApplyOneTemplate: copy node root xsltApplyTemplates: list of 1 nodes xsltProcessOneNode: applying template 'y|/*' for x xsltApplyOneTemplate: copy text Matched /* or y template xsltApplyTemplates: node: x xsltApplyTemplates: list of 1 nodes xsltProcessOneNode: no template found for text xsltDefaultProcessOneNode: copy text <?xml version="1.0"?> <root>Matched /* or y template </root> orchis:~/XSLT/tests/general -> Oh, BTW use the -v flag to debug what's happening during a run. thanks again for the good bug report, Daniel
should be closed in th 2.3.12 release, thanks for the report ! Daniel