xsl-list
[Top] [All Lists]

Re: Random Namespaces Declared with XSLT Stylesheet... why?

2003-06-19 08:51:52
Jimmy Cerra wrote:
I've been hacking a quick-and-dirty transform for turning a custom
language [1] into HTML (for presentation), but I've got some odd
behavior.  The stylesheet seems to randomly put namespace declarations
where they're not needed.  Why is it doing this?

Namespace nodes corresponding to in-scope namespaces are attached to literal
result elements in your stylesheet. These nodes are copied to the result tree
along with the elements. 

When the processor serializes the result tree, it typically does so as soon as
it can -- i.e., it writes out a start tag for an element node before it has
generated all of that node's descendants. In this situation, the processor
can't predict what namespace declarations will be needed by the descendants,
so to be safe, it immediately generates in the start tag whatever namespace
declarations are necessary to reflect changes in the bindings that are in
scope.

One might argue that even if the serialization is done after the result tree
is complete, any "unused" namespace nodes should still be serialized, just by
virtue of their presence in the result tree, because their presence may be
deliberate and may affect further processing of that tree.

You should investigate the use of xsl:element and xsl:attribute to create
elements and attributes that don't inherit namespace nodes from the
stylesheet. You may also rely on exclude-result-prefixes="foo bar baz" on the
xsl:stylesheet or xsl:transform element to dissuade the processor from
serializing declarations for the namespaces bound to those prefixes in the
stylesheet.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list