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: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 22 Mar 2007 15:23:34 +0100
At 2007-03-22 15:08 +0100, Abel Braaksma wrote:
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
'test:other-ns-now' element.

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)?

Because your use of exclude-result-prefixes= has pruned the namespace node away from the <root> literal result element.


If I read your words correctly, this should not be allowed to happen, but it does:

What you see is precisely what I would expect.


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,

False. The namespace node has been pruned away from the <root> element so does not require a declaration. The node cannot be pruned from a literal-result-element that needs it. Saxon places the namespace declaration where it needs it and not anywhere higher.


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',

Correct ... because you haven't pruned it off of that literal result element.


I think David's assertion is still correct ... it cannot be moved "down" the tree ... the declaration is placed where there is a namespace node in the result tree and your examples of pruning or not pruning the namespace nodes impact on the presence of a namespace node on your <root> result element.

I'm still wary of a processor moving the namespace declaration "up" the tree ... though not incorrect (assuming they haven't confused namespaces), I don't see how the result tree node has namespace nodes requiring declarations ... surely they are not moved up the tree. Why would a processor bother with the look-ahead to determine "future" use of namespace nodes? But he is correct to say that it is not incorrect.

I hope this helps.

. . . . . . . . . . Ken

--
World-wide corporate, govt. & user group XML, XSL and UBL training
RSS feeds:     publicly-available developer resources and training
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0    +1(613)489-0999 (F:-0995)
Male Cancer Awareness Aug'05  http://www.CraneSoftwrights.com/s/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal

Current Thread