RE: [xsl] How to prevent that XML attributes ares

Subject: RE: [xsl] How to prevent that XML attributes ares
From: Jérôme Haguet <j.haguet@xxxxxxxxxx>
Date: Thu, 23 Feb 2006 10:49:34 +0100
What about this ?
It seems to work fine.

  <xsl:template match="jasperReport/@isFloatColumnFooter |
jasperReport/@isIgnorePagination | image/@isLazy">
    <xsl:if test=". != 'false'">
      <xsl:copy/>
    </xsl:if>
  </xsl:template>

Jirtme Haguet
Stratigies - France
http://www.cadwin.com

-----Message d'origine-----
De : Jirtme Haguet
Envoyi : jeudi 23 fivrier 2006 10:21
@ : 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
Objet : Re: [xsl] How to prevent that XML attributes ares

Hi Wendell

In fact, I did try what you suggested before to send the first email to the
list

It is not good because it will always delete - for example - the attribute
isIgnorePagination
And in some of the XML documents, it is set to "true", which is not the
default value ...

So I need something like :
	<xsl:template match="@isIgnorePagination='false'"/>
which is not correct, I know this.

Any idea how to write such a condition in a concise way ?

Jirtme Haguet
Stratigies - France
http://www.cadwin.com

-----Message d'origine-----
Date: Wed, 22 Feb 2006 14:33:53 -0500
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Subject: Re: [xsl] How to prevent that XML attributes ares
  automatically added ?
Message-Id: <7.0.0.16.0.20060222142600.037a23e8@xxxxxxxxxxxxxxxx>

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