[xsl] Can one _generate_ namespace nodes?

Subject: [xsl] Can one _generate_ namespace nodes?
From: Joseph Kesselman <keshlam@xxxxxxxxxx>
Date: Fri, 21 Feb 2003 19:24:08 -0500
I've got a situation where I'm using namespace aliasing. It's working 
fine, but the output (using Xalan, at least) is a bit ugly; the serializer 
doesn't realize that the new prefix binding is required until it gets down 
to the aliased nodes, and generates the binding there. Since these are 
scattered throughout the document, that means a lot of namespace 
declaration nodes.

I'd prefer to declare the new prefix once, at the top of the generated 
document. But there doesn't seem to be a way to express that. There's no 
<xsl:namespace-node> to go with <xsl:attribute>, and <xsl:attribute> is 
explicitly forbidden to generate namespace declarations. (Actually, the 
way it's forbidden doesn't work now that namespaces have been redefined to 
be namespace-aware rather than being hardcoded to the xmlns: prefix, but 
that's a separate matter.)

I could generate a dummy attribute with the correct prefix and namespace 
at the top level, and let that imply a declaration -- but that could break 
validation of the generated document, and sometimes it's explicitly 
forbidden. (If I'm generating a stylesheet element, I'd have to create an 
attribute in the same namespace as xsl: -- but those are reserved for 
XSL's use, and there isn't one which is officially legal on an 
<xsl:stylesheet> element.)

I say again, this is an attempt to fix a purely cosmetic problem... but it 
really feels like there ought to be a solution. If anyone *does* know of 
an official and reliable way to generate a namespace declaration into a 
document at a specific point, I'd appreciate the tip!

If not... well, the article goes out as "it's ugly but it works."

Joe Kesselman, IBM Next-Generation Web Technologies:
XML, XSL and more.  "may'ron DaroQbe'chugh vaj bIrIQbej" 
("Put down the squeezebox and nobody gets hurt.")

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

Current Thread