[xslt] xslt and duplicated attributes (comment on bugzilla bug #86753)
- From: Morus Walter <morus walter tanto-xipolis de>
- To: xslt gnome org
- Subject: [xslt] xslt and duplicated attributes (comment on bugzilla bug #86753)
- Date: Tue, 2 Jul 2002 16:54:04 +0200
Hi,
(though I think the problem is in libxml I choose the xslt list,
since the bug I'm commenting is connected to the libxslt project, and
the problems show up in libxslt)
I would like to add some comments on bugzilla bug #86753
(http://bugzilla.gnome.org/show_bug.cgi?id=86753)
I ran into a similar problem, which is illustrated by the following
simple test case:
--- test.xml ---
<bla><blub att1="di"/><foo att2="di"/><bar att3="di"/></bla>
----------------
--- test.xsl ---
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="no" encoding="ISO-8859-1" method="xml"/>
<xsl:template match="bla">
<bla>
<xsl:attribute name="new"><xsl:text>style 1</xsl:text></xsl:attribute>
<xsl:attribute name="new"><xsl:text>style 2</xsl:text></xsl:attribute>
<xsl:apply-templates/>
</bla>
</xsl:template>
<xsl:template match="blub">
<out att1="style">
<xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
<xsl:apply-templates/>
</out>
</xsl:template>
<xsl:template match="foo">
<xsl:copy>
<xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
<xsl:attribute name="att2"><xsl:text>style</xsl:text></xsl:attribute>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="bar">
<xsl:copy>
<xsl:attribute name="att3"><xsl:text>style</xsl:text></xsl:attribute>
<xsl:for-each select="@*"><xsl:copy/></xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
-----------
using xsltproc this gives:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bla new="style 2"><out att1="style" att1="di"/><foo att2="style"/><bar att3="style" att3="di"/></bla>
showing that attribute handling goes wrong for the first and last child
of the 'bla' element.
libxslt addes an attribute, that is copied with xsl:copy even if the
attribute is already there.
(Things get even worse, if one uses multiple <xsl:copy/> elements
(<xsl:for-each select="@*"><xsl:copy/><xsl:copy/><xsl:copy/></xsl:for-each>)
which does not make sense but should not cause harm.)
Overwriting attributes works, if they are created by <xsl:attribute>, OTOH.
xalan (c++), xalan (java), xt and saxon have the result:
<?xml version="1.0" encoding="ISO-8859-1"?>
<bla new="style 2"><out att1="di"/><foo att2="style"/><bar att3="di"/></bla>
I had a look at it in the debugger:
The problem seems to come from copying attributes using xmlCopyProp
(libxml tree.c:2748) for the attributes copied with xsl:copy.
This function does not seem to take care of existing attributes (as oposed
to the xmlSetProp function which is used by xsl:attribute handling).
I think xmlCopyProp would be the right place to fix the xslt problems.
Sorry, I don't have a patch, but I thought my notes on this problem
might be of interest anyway.
I didn't examine in detail how the duplicate attribute is created
in the case of bug #86753 (looks rather complicated), but I think
there is at least a good chance, that this is a result of the same
bug.
It might be worth noting, that a similar problem was reported on the
xslt mailing list by Janning Vygen in the context of attribute sets
(http://mail.gnome.org/archives/xslt/2002-April/msg00051.html).
greetings
Morus
PS: I would have added a comment on the bug in bugzilla but I don't think
that I have the rights to do so...
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]