Re: [xsl] How to prevent that XML attributes ares automatically added ?

Subject: Re: [xsl] How to prevent that XML attributes ares automatically added ?
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Wed, 22 Feb 2006 14:33:53 -0500
Hi Jerome,

At 12:36 PM 2/22/2006, you wrote:
Basically, it works.

Except one thing : in some cases, it adds some attributes to some XML elements.
I guess that this happens in order that the final XML become compliant with the DTD specified in the top of the source XML file.
If I delete the DTD directive, no attributes are added.

You are almost half right. This is not happening so that the result be valid to the source's DTD. Most of the time that would be a bad idea and undesirable.


Rather, you are apparently doing a near-identity transformation, in which most of what the stylesheet is doing is simply copying the input to the result. But your DTD contains attribute declarations that provide default values to some of the attributes in your document. Accordingly, when your DOCTYPE declaration is in place, the parsed document (the tree-shaped thing on which the transform actually operates) contains the attributes -- which then get copied along with the rest.

If you want these not to be there, simply write your stylesheet to suppress them instead of copying them.

Depending on how your identity transformation is constructed, this can be as easy as:

<xsl:template
match="@isFloatColumnFooter | @whenResourceMissingType | @isIgnorePagination"/>


Alternatively, ensure that the DTD is not used by removing or commenting out the DOCTYPE declarations in your input; as you've found, the defaulted attributes won't then be copied to the result. But the first solution is less of a hack.

Cheers,
Wendell


Here above is an example of the added attributes :


<!DOCTYPE jasperReport PUBLIC "//JasperReports//DTD Report Design//EN" "http://jasperreports.sourceforge.net/dtds/jasperreport.dtd";>
<jasperReport ...isFloatColumnFooter="false" whenResourceMissingType="Null" isIgnorePagination="false">
...
</jasperReport>


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread