Re: [xslt] overwriting attributes



Am Dienstag, 23. April 2002 11:23 schrieben Sie:
> On Tue, Apr 23, 2002 at 11:14:52AM +0200, Janning Vygen wrote:
> > Hi,
> >
> > i found something weired in xsltproc/libxslt. I searched the bug
> > archive but didnt found anything.
> >
> > I produced an html file from an xml file and it shows up with two
> > attributes of the same name in one element, which is an error,
> > right?
> > here comes a part of the xsl code...

[... new code comes below]

> >
> > normally the second attribute should owerwrite the first. At
> > least Michael Kay say so in XSLT Programmers Reference and for me
> > it seems to be convinient.
>
>   Hum, could you isolate this into a full small but complete XSLT
> and the associated XML example so I can reproduce it easilly ?

here you are:

----- XSL Stylesheet -------------
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
              xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:template match="@*|node()">
  <xsl:copy>
    <xsl:apply-templates select="@*|node()"/>
  </xsl:copy>
</xsl:template>

<xsl:attribute-set name="table.defaults">
  <xsl:attribute name="border">0</xsl:attribute>
  <xsl:attribute name="cellpadding">0</xsl:attribute>
  <xsl:attribute name="cellspacing">0</xsl:attribute>
</xsl:attribute-set>

<xsl:template match="table">
  <xsl:copy use-attribute-sets="table.defaults">
    <xsl:for-each select="@*">
      <xsl:copy/>
    </xsl:for-each>
    <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

</xsl:stylesheet>

----- XML DOC ------------------
<?xml version="1.0" encoding="iso-8859-1"?>
<bug>
  <table border="3">
    <tr><td>first table with border = 3</td></tr>
  </table>

  <table cellpadding="3" border="2">
    <tr><td>first table with cellpadding = 3</td></tr>
    <tr><td> and border=2</td></tr>
  </table>
</bug>
----- RESULT from xsltproc ------
<?xml version="1.0"?>
<bug>
  <table border="0" cellpadding="0" cellspacing="0" border="3">
    <tr><td>first table with border = 3</td></tr>
  </table>

  <table border="0" cellpadding="0" cellspacing="0" cellpadding="3" 
border="2">
    <tr><td>first table with cellpadding = 3</td></tr>
    <tr><td> and border=2</td></tr>
  </table>
</bug>
----------------------------------

both tables in the result have attributes with the same name!

regards,
janning


-- 
Planwerk 6 /websolutions
Herzogstraße 86
40215 Düsseldorf

fon 0211-6015919
fax 0211-6015917
http://www.planwerk6.de



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]