GNOME Bugzilla – Bug 335298
Duplicate templates with same name no longer allowed
Last modified: 2006-03-22 15:56:25 UTC
Please describe the problem: libxslt-1.0.1-3 for RedHat 7.2 used to allow multiple xsl:template elements with the same name, and ones with a higher priority would take precedence. Now, with libxsl-1.1.14-2 on Fedora Core 4, this is mysteriously no longer allowed. Consider this xsltproc output: xsltproc -V template.xsl document.xml Using libxml 20619, libxslt 10114 and libexslt 812 xsltproc was compiled against libxml 20619, libxslt 10114 and libexslt 812 libxslt 10114 was compiled against libxml 20619 libexslt 812 was compiled against libxml 20619 compilation error: file template.xsl line 18 element template xsl:template: error duplicate name 'buttons' Contents of "document.xml" file: <?xml version="1.0"?> <doc> <foo>bar</foo> </doc> Contents of "template.xsl" file: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="UTF-8" media-type="text/html"/> <xsl:preserve-space elements="*"/> <xsl:template match="/"> <xsl:text>foo!</xsl:text> </xsl:template> <xsl:template name="buttons" priority="1"> <table width="100%"> <tr> <td width="100%"></td> </tr> </table> </xsl:template> <xsl:template name="buttons" priority="2"> <table width="100%"> <tr> <td width="100%"></td> </tr> </table> </xsl:template> </xsl:stylesheet> Now, consider the same test run on libxslt-1.0.1-3 on RedHat 7.2: xsltproc -V template.xsl document.xml Using libxml 20410, libxslt 10001 and libexslt 200 xsltproc was compiled against libxml 20401, libxslt 10001 and libexslt 200 libxslt 10001 was compiled against libxml 20401 libexslt 200 was compiled against libxml 20401 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC- html40/loose.dtd"> foo! That is the expected output. Any idea why version 1.1.14-2 would suddenly reject this template? Steps to reproduce: 1. Upload attached files document.xml and template.xsl 2. Run command xsltproc -V template.xsl document.xml 3. See output Actual results: xsltproc outputs the following error: compilation error: file template.xsl line 18 element template xsl:template: error duplicate name 'buttons' Expected results: The document should be transformed, and "foo!" outputted, as it does using libxslt-1.0.1-2. There should be no error generated. Does this happen every time? Yes. Other information: See attached files "document.xml" and "template.xsl"
Created attachment 61650 [details] XSLT template containing duplicate xsl:template elements with same name
Created attachment 61651 [details] Sample document XML for transformation using template.xsl
http://www.w3.org/TR/xslt#named-templates "It is an error if a stylesheet contains more than one template with the same name and same import precedence" if in the same .xsl they have same import precedence, so clearly it is an error. You relied on a bug which has been fixed since. Daniel
I'm sorry, I tried to simplify the problem in the bug description by including both named templates in the same file. In my ACTUAL application, one is from an xsl:include, while the other is in the main document, and the problem still occurs (same error message). According to the XSLT specification, the included file has a lower precedence, so there shouldn't be any error generated. Please see the attached template2.xsl and include2.xsl. Use the same document.xml, and run this command: xsltproc template2.xsl document.xml The template2.xsl includes the include2.xsl file, which contains one copy of the "buttons" template. The main template2.xsl also contains another copy of the "buttons" template. Since the included file has a lower precedence, there shouldn't be any error generated, right?
Created attachment 61703 [details] XSL template which includes the include2.xsl file This template is for illustrating if you include a separate file which contains a duplicate of a function, there should be no error generated because the precedence is lower.
Created attachment 61704 [details] This file is included in template2.xsl This file contains a lower-precedence copy of the "buttons" function, which should be overridden by the copy in the main template2.xsl file.
I think you are slightly mistaken. You are confusing xsl:include and xsl:import. The behaviour of libxslt previously had a similar confusion, and this was fixed as a result of bug 151795. The fix was released in libxslt-1.1.11 (29 Sept 04). If you change your "include" to be an "import" you should get the behaviour which you expect.
Thank you, William, you are exactly correct. I am an idiot, and am closing this bug. Sorry for the false report.