Re: [xsl] I need to make sure that all namespace declarations get output to a particular element, not the document element
Subject: Re: [xsl] I need to make sure that all namespace declarations get output to a particular element, not the document element|
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Thu, 22 Mar 2007 15:08:07 +0100
David Carlisle wrote:
Not sure if the processor is allowed to, I think it is, to cleanup the
namespaces the way it likes and instead put the namespace decl. to
That wouldn't be allowed, The XSLT1 output serialisation is allowed to
move declarations up the tree, meaning a namespace is in scope earlier
than one might expect, but it can never move a namespace declaration
down the tree. If an element node in the result has a namespace node
(even if that namespace is not used in any element or attribute) the
namespace declaration must be serialised on the element or an ancestor.
How then, would you explain the behavior that in the following
stylesheet, the namespace declaration created before it is used, but in
the serialized output, it is placed on a descendant (namely the
descendant that first uses the namespace)? If I read your words
correctly, this should not be allowed to happen, but it does:
<xsl:output indent="yes" />
will result in (Saxon 6.5.5)
which means, imo, that the declaration for the 'http://www.xyz.com'
namespace, which is put on the RLE 'elem' is moved to an descendant,
namely the 'test:other-ns-now' element.
This does not change the output in any way, except for the location of
the namespace declaration. If I remove the exclude-result-prefixed, the
namespace is put on 'root', if I remove the namespace declaration the
'http://www.xyz.com' namespace from the xsl:stylesheet, the namespace
declaration is left in the serialized output tree where I originally put
in the stylesheet: the element 'test:other-ns-now'.
I personally never worry about namespaces. They always work correctly.
And whether there's cleanup or not, I never encountered a situation
where a namespace is declared after it is used (which would make the XML
invalid to what is requested in your stylesheet declarations).
-- Abel Braaksma