RE: [xsl] Creating namespace declarations solely for QName attribute values

Subject: RE: [xsl] Creating namespace declarations solely for QName attribute values
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 16 Oct 2008 23:16:57 +0100
> No, I was trying to use XSLT 1.0.  Is this possible?
> 
> It's easy to do it with a DOM traversal, but XSLT is supposed 
> to be Turing complete, isn't it.

Being Turing complete doesn't mean you can cook an omelette (or even create
namespace nodes).

In fact there are techniques in 1.0 if you really can't move forward (but
you have my deepest sympathy if you have to use them). You can't create
arbitrary namespace nodes, but you can copy them. The usual technique is to
create a result tree fragment containing an element in the required
namespace, then use the xx:node-set() extension to convert the RTF to a
node-set, then use the namespace axis to copy the generated namespace node
from this node-set to the result tree. This depends on a 1.0 extension - in
the general case I think it *can't* be done with pure XSLT 1.0.

Michael Kay
http://www.saxonica.com/

> 
> Jeff
> 
> Michael Kay wrote:
> > Are you using XSLT 2.0? The xsl:namespace instruction was 
> invented to 
> > make this kind of job easier.
> >
> > Michael Kay
> > http://www.saxonica.com/
> >  
> >
> >   
> >> -----Original Message-----
> >> From: Jeff Greif [mailto:jeff.greif@xxxxxxxxx]
> >> Sent: 16 October 2008 22:45
> >> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >> Subject: [xsl] Creating namespace declarations solely for QName 
> >> attribute values
> >>
> >> 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