My article on styling stylesheets had some comments on the hassles of
trying to get specific namespace declarations into your ouput document. The
best way to control exactly which prefix is generated, and to force
specific namespace nodes, is currently to generate results using
<xsl:element> and/or <xsl:attribute> rather than literal result elements...
and even there, I believe the serializer might would be within its rights
to change the prefix.
Second best choice right now is a particularly ugly idiom for explicitly
generating and copying a Namespace Node:
<xsl:variable name="dummy">
<xsl:element name="tracexsl:x" namespace="http://www.my.net/my
markup"/>
</xsl:variable>
<xsl:copy-of select="xx:node-set($dummy)//namespace::*"/>
(XSLT 2.0 has proposed adding an <xsl:namespace> directive which would be a
cleaner way to achieve this.)
Personally, I'm a purist: The namespaces spec says prefixes are just
shorthand for namespace URIs, so you really shouldn't be worrying about
which prefix appears as long as it was bound correctly. That doesn't
address the problem of folks having used prefixes inside data strings and
expecting them to match the current namespace context... but I've always
considered that usage somewhat broken, precisely because it *IS* so hard
for namespace-aware XML processing to maintain. Yes, XPath and XSLT
themselves are examples of why folks want to do this and how it sometimes
breaks; I would have preferred that XSLT have its own parallel declaration
of prefixes that appear within the XPaths, despite the increased verbosity.
Oh well. It is what it is, and we live with it...
______________________________________
Joe Kesselman, IBM Next-Generation Web Technologies: XML, XSL and more.
"The world changed profoundly and unpredictably the day Tim Berners Lee
got bitten by a radioactive spider." -- Rafe Culpin, in r.m.filk