[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] How to avoid adding defaulted attributes

Subject: Re: [xsl] How to avoid adding defaulted attributes
From: Graydon <graydon@xxxxxxxxx>
Date: Thu, 9 Jan 2014 20:11:59 -0500

On Thu, Jan 09, 2014 at 04:53:30PM -0800, Mark Giffin scripsit:
> I am running an identity transform on some files and changing a few
> things as they pass through. They are DITA XML files and their DTDs
> have defaulted attributes that do not appear in the instance files.
> But during the transform the defaulted attributes are added in on
> elements that I do not explicitly handle with XSLT templates. I can
> stop this behavior by commenting out the doctypes, but is there a way
> to do this with some setting? I'm using Saxon PE

No setting.

Fixed or default attributes appear when the document gets parsed against
the DTD -- and any document has to be parsed for XSLT to do anything
whatsoever to it -- and then show up in your output because they really
are there in the input tree, even if they're not in the file version of
the source document.

The two options are to avoid the association with the DTD that provides
the fixed or default attributes at parse time -- commenting out the
doctype declaration, as you note, or doing a happy dance with an initial
transform that both fails to create the doctype declaration and scrubs
the fixed attributes, and then doing the interesting processing on that,
with the interesting processing step putting the doctype declaration
back -- or to include templates in the transform to drop the fixed or
default attributes during the transform.

I find the second approach is generally simpler and cleaner, so long as
there aren't many fixed attributes to deal with.  If there's a bunch,
encapsulating the scrubbing step into a single transform can be worth
it, especially if you're going to re-use it with other small transforms
on the same content.

If you've got some explicitly present attributes in the input that are
otherwise defaulted, this gets much nastier, because the transform has
to be able to tell the "really there" attributes from the defaulted
attributes, and preserve the former while disposing of the later.

-- Graydon

Current Thread