[xsl] Creating namespace declarations solely for QName attribute values

Subject: [xsl] Creating namespace declarations solely for QName attribute values
From: "Jeff Greif" <jeff.greif@xxxxxxxxx>
Date: Thu, 16 Oct 2008 14:44:30 -0700
We are trying to replace namespaces consistently in the namespace
declarations of a document, thus preserving the prefixes so the QName
attribute values remain valid.

That is, given a source document like this:

<schema targetNamespace="urn:target" xmlns:t="urn:target"
xmlns:i="urn:imported">
 <import namespace="urn:imported"/>
 <element name="something" type="i:ImportedType"/>
</schema>

The key feature of this document is that no element or attribute in
the document is in either of the explicitly declared namespaces.
These namespaces are only referenced explicitly in attribute values
and implicitly in the QName-valued attribute 'type'.

The idea is to change urn:target to urn:target1 and urn:imported to
urn:imported1 (based on a map of these conversions read into the XSLT
using the document() function).  None of the namespaces involved in
this conversion can be declared in the stylesheet, but are determined
from the map.

We know how to change the value of any attribute, the namespace of any
element or attribute using this map, but we don't see yet how to
change the association of a prefix with a namespace, so that the
prefix 'i' will be associated with the namespace "urn:imported1" in
the result document, effectively changing the namespace implied by the
value of the 'type' attribute in the result document, *when there is
no element or attribute in the source document that has the namespace
corresponding to that prefix*.

We are trying to avoid having to know which are attributes with QName
values and having to transform their values to somehow conform to
prefixes used in the result doc.

Is there a way to do this in XSLT, given that matching on namespace
nodes is not possible, and we have been unable to find a way to create
namespace nodes in a template except by naming an element or attribute
using the prefix in question?  Would a solution involve creating an
attribute with the given prefix and namespace, to change the namespace
nodes of the containing element, while avoiding having the attribute
appearing in the result document?

Jeff

Current Thread