After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 335298 - Duplicate templates with same name no longer allowed
Duplicate templates with same name no longer allowed
Status: RESOLVED NOTABUG
Product: libxslt
Classification: Platform
Component: general
1.1.14
Other All
: Normal normal
: ---
Assigned To: Daniel Veillard
libxml QA maintainers
Depends on:
Blocks:
 
 
Reported: 2006-03-20 23:58 UTC by Joseph Huckaby
Modified: 2006-03-22 15:56 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
XSLT template containing duplicate xsl:template elements with same name (567 bytes, text/plain)
2006-03-21 00:00 UTC, Joseph Huckaby
Details
Sample document XML for transformation using template.xsl (52 bytes, text/plain)
2006-03-21 00:00 UTC, Joseph Huckaby
Details
XSL template which includes the include2.xsl file (474 bytes, text/plain)
2006-03-21 17:03 UTC, Joseph Huckaby
Details
This file is included in template2.xsl (267 bytes, text/plain)
2006-03-21 17:04 UTC, Joseph Huckaby
Details

Description Joseph Huckaby 2006-03-20 23:58:29 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"
Comment 1 Joseph Huckaby 2006-03-21 00:00:14 UTC
Created attachment 61650 [details]
XSLT template containing duplicate xsl:template elements with same name
Comment 2 Joseph Huckaby 2006-03-21 00:00:51 UTC
Created attachment 61651 [details]
Sample document XML for transformation using template.xsl
Comment 3 Daniel Veillard 2006-03-21 00:05:13 UTC
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
Comment 4 Joseph Huckaby 2006-03-21 17:01:11 UTC
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?
Comment 5 Joseph Huckaby 2006-03-21 17:03:30 UTC
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.
Comment 6 Joseph Huckaby 2006-03-21 17:04:41 UTC
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.
Comment 7 William M. Brack 2006-03-22 15:48:13 UTC
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.
Comment 8 Joseph Huckaby 2006-03-22 15:56:25 UTC
Thank you, William, you are exactly correct.  I am an idiot, and am closing this bug.  Sorry for the false report.