On Apr 8, 2008, at 1:57 AM, Michael Kay wrote:
I have a stylesheet which I use to normalize various versions of a
DTD. Some old XML documents created against this DTD do
not include a default namespace declaration on the root element
but the
newer ones do, and I think the way I have to handle this is to have
two templates in my stylesheet, one of which selects root elements
without
a
namespace and one which does:
Since the default namespace declaration changes the namespace of every
element in the document, not just the root element, my preferred
approach to
this kind of problem is to write your stylesheet to handle the case
with a
namespace, and then insert an extra stage into your processing
pipeline to
add the namespace for the older documents that don't have it. This
keeps
things much more simple and modular, and allows you to throw away the
non-namespace code when the problem is resolved at source.
That's essentially what my "normalizer" does. The stylesheet in
question is a preprocessor which restructures the older documents -
adds the namespace, addresses DTD differences between versions, etc.
- and makes them valid against the current DTD prior to the main
processing in a different stylesheet which is linked to the
normalizer via JAXP. The template that processes older document
roots directs processing of the older child nodes by using templates
with modes, while newer documents are passed through essentially
unchanged. I did it this way so that I could run the normalizer
against any document regardless of its age, since determining the
vintage up front requires opening the document in some mode (unparsed
text or XML) anyway.
Cheers
Chris
--~------------------------------------------------------------------
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>
--~--