7.1.5 Creating namespace declarations with xsl:namespace-declaration

Subject: 7.1.5 Creating namespace declarations with xsl:namespace-declaration
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 21 Dec 1999 16:21:29 GMT
section 7.1.3 says that I can add an attribute to the current element in
the result tree like so 

<foo>
<xsl:attribute name="x">this</xsl:attribute>

or if I want to copy all the attributes from the current node

<foo>
<xsl:copy-of select="@*"/>

But there is nothing equivalent for namespace declarations.

I want to produce an element foo in the result tree that has (at least) 
the namespace declarations of the current node.

In the special case that the node in the result tree has the same qname
as the current node, I can use xsl:copy, but if not then I would like to
do

<foo>
<xsl:copy-of select="namespace::*"/>

The spec is distinctly unclear what is supposed to happen if you copy a
namespace node. xt doesn't support the namespace axis, and saxon does
as a query, but doesn't seem to copy namespace nodes to the output (and
It's not clear to me that it should, although that would be useful)


I finally managed to acheive what I want by

wrapping the body of my template in <xsl:copy> ...</xsl:copy>
which put all the result tree nodes in scope of the necessary namespace
declaration, and then had a second stylesheet that was an identity
transform except that it removed the unwanted copied elements (leaving
their contents) (XSLT then automatically shifts the namespace
declarations on to the remaining elements)

Is there a better way in xslt 1.0?

The context of this is an xpath aware input language with an input
node looking like

 <rule context="om:OMS">

with om: prefix being declared somewhere above.

I am transforming this to an xsl stylesheet so it ends up looking like


<axsl:template match="om:OMS">

so, I need to generate a namespace declaration in the result tree for
om: prefix even though there is no attribute or element in the openmath
namespace.

David


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


Current Thread