xsl-list
[Top] [All Lists]

Re: [xsl] How to avoid adding defaulted attributes

2014-01-09 19:12:11
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 9.4.0.6.

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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--