RE: [xsl] [XSL] copying namesapces with prefix "xmlns:".

Subject: RE: [xsl] [XSL] copying namesapces with prefix "xmlns:".
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Fri, 26 Aug 2005 13:33:23 +0100
The Saxon 6.x behavior here is not the only possible interpretation of the
1.0 spec.

Erratum E25 says, in relation to copying of namespace nodes, "It is an error
to add a namespace node to an element if the element already has a namespace
node with the same name".

Given this code:

    <xsl:element name="definitions">
        <xsl:copy-of select="namespace::*"/>

Saxon is evaluating top-down; it creates the <definitions> element in the
results, decides on a namespace prefix, creates a namespace node binding
that prefix to the relevant URI, and then goes on to evaluate the
xsl:copy-of instruction, at which point it hits the error that there's
"already" a namespace node with the same name. However, the result depends
on order of execution; if it had deferred choosing the namespace prefix
until all the namespace nodes were known, it could have avoided the error -
and this is what the XSLT 2.0 spec (with its bottom-up execution model)
requires.


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

> -----Original Message-----
> From: David Carlisle [mailto:davidc@xxxxxxxxx] 
> Sent: 26 August 2005 12:33
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: Re: [xsl] [XSL] copying namesapces with prefix "xmlns:".
> 
> 
> 
> saxon6 (XSLT 1) says:
> 
> $ saxon bo.xml bo.xsl
> Error at xsl:copy-of on line 11 of file:/c:/tmp/bo.xsl:
>   Cannot create two namespace nodes with the same name
> Transformation failed: Run-time errors were reported
> 
> saxon8 (XSLT2) says: (my indentation)
> $ saxon8 -novw bo.xml bo.xsl
> <?xml version="1.0" encoding="UTF-8"?>
> <_0:definitions
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>   xmlns:xpdl="http://www.wfmc.org/2002/XPDL1.0";
>   xmlns:h2w="http://test.de/h2w/bo/";
>   xmlns:bo="http://test.de/bo/";
>   xmlns="http://www.wfmc.org/2002/XPDL1.0";
>   xmlns:_0="http://test.de/schemas/wfdl/";>
> <FlowModel xmlns="ht
> tp://test.de/schemas/wfdl/"/>
> </_0:definitions>
> 
> 
> 
> So perhaps xslt2 does what you want (it depends what you want).
> The problem is that you have conflicting definitions of the default
> namespace:
> 
> The result tree already has
> 
> xmlns="http://test.de/schemas/wfdl/";
> 
> from the stylesheet, and then you are copying
> 
> xmlns="http://www.wfmc.org/2002/XPDL1.0";
> 
> from the source.
> 
> In xslt1 this is an error in xslt2 the first one gets 
> renamed. (Actually
> I haven't checked the spec again, but that's what saxon dows)
> 
> You could copy all the ones except the default namespace with
>         <xsl:copy-of select="namespace::*[name()]"/>
> 
> which in saxon6 gives:
> $ saxon bo.xml bo.xsl
> <?xml version="1.0" encoding="utf-8"?>
> <definitions
>   xmlns="http://test.de/schemas/wfdl/";
>   xmlns:bo="http://test.de/bo/";
>   xmlns:h2w="http://test.de/h2w/bo/";
>   xmlns:xpdl="http://www.wfmc.org/2002/XPDL1.0";
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";>
> <FlowModel/>
> </definitions>
> 
> 
> and in saxon8 gives
> $ saxon8 -novw bo.xml bo.xsl
> <?xml version="1.0" encoding="UTF-8"?>
> <definitions
>   xmlns="http://test.de/schemas/wfdl/";
>   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>   xmlns:xpdl="http://www.wfmc.org/2002/XPDL1.0";
>   xmlns:h2w="http://test.de/h2w/bo/";
>    xmlns:bo="http://test.de/bo/";>
> <FlowModel/>
> </definitions>
> 
> David
> 
> ______________________________________________________________
> __________
> This e-mail has been scanned for all viruses by Star. The
> service is powered by MessageLabs. For more information on a proactive
> anti-virus service working around the clock, around the globe, visit:
> http://www.star.net.uk
> ______________________________________________________________
> __________

Current Thread