[oXygen-user] XSLT output root element force namespaces and attributes sequence

George Cristian Bina
Wed May 26 02:49:31 CDT 2010


Dear Marijn,

The XML namespace http://www.w3.org/XML/1998/namespace bound to the 
"xml" prefix is declared by default in any XML document. Thus, it does 
not need to be declared. If declared then it needs to be always bound to 
the "xml" prefix.
Even in your XSLT fragment the declaration is redundant because it is 
always added by the namepsace fixup, see
http://www.w3.org/TR/xslt20/#namespace-fixup
***
Every element must have a namespace node whose expanded-QName has 
local-part xml and whose string value is 
http://www.w3.org/XML/1998/namespace. The namespace prefix xml must not 
be associated with any other namespace URI, and the namespace URI 
http://www.w3.org/XML/1998/namespace  must not be associated with any 
other prefix.
***

Note also at the same location:
***
The actual namespace nodes that are added to the tree by the namespace 
fixup process are implementation-dependent, provided firstly, that at 
the end of the process the above constraints must all be satisfied, and 
secondly, that

*a namespace node must not be added to the tree unless the namespace 
node is necessary either to satisfy these constraints, or to enable the 
tree to be serialized using the original namespace prefixes*

from the source document or stylesheet.
***

As the XML namespace is not needed (it is present in any XML document) 
the XSLT processor does not add it when the result is serialized.


The XSLT spec for serialization does not require a specific order for 
namespace declarations and attributes, thus you cannot force a specific 
order. You can observe how a specific version of a specific processor 
works and maybe rely on that but you should also be prepared to have a 
different order as soon as you change the processor or upgrade to a 
different version.
As a reference in the spec please see
http://www.w3.org/TR/xslt-xquery-serialization/#reconstructed-tree
***
The order of attribute and namespace nodes in the two trees MAY be 
different.
***

Best Regards,
George
-- 
George Cristian Bina
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

On 5/25/10 4:58 PM, Martijn Van der Graaff wrote:
> Hi
>
> I need to generate a root element in a output file that contains some attributes and namespaces.
>
> It should like this:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <enfinity xsi:schemaLocation="http://www.intershop.com/xml/ns/enfinity/6.2.2/xcs/impex catalog.xsd http://www.intershop.com/xml/ns/enfinity/6.1/core/impex-dt dt.xsd"
>            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>            xmlns="http://www.intershop.com/xml/ns/enfinity/6.2.2/xcs/impex"
>            xmlns:xml="http://www.w3.org/XML/1998/namespace"
>            xmlns:dt="http://www.intershop.com/xml/ns/enfinity/6.1/core/impex-dt"
>            major="6"
>            minor="1"
>            family="enfinity"
>            branch="enterprise"
>            build="6.3.1.2.5">
>
> what I get is this:
>
> <enfinity xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>            xmlns="http://www.intershop.com/xml/ns/enfinity/6.2.2/xcs/impex"
>            xmlns:dt="http://www.intershop.com/xml/ns/enfinity/6.1/core/impex-dt"
>            xsi:schemaLocation="http://www.intershop.com/xml/ns/enfinity/6.1/xcs/impex catalog.xsd http://www.intershop.com/xml/ns/enfinity/6.1/core/impex-dt dt.xsd"
>            major="6"
>            minor="1"
>            family="enfinity"
>            branch="enterprise"
>            build="6.3.1.2.5">
>
> How can I force in XSLT that (xmlns:xml="http://www.w3.org/XML/1998/namespace") is always added to the root element and how can I force on where the attributes are sorted.
>
> My xslt snippet is:
>
> <xsl:template match="/"...
>    <xsl:element name="enfinity" namespace="http://www.intershop.com/xml/ns/enfinity/6.2.2/xcs/impex">
>              <xsl:attribute name="xsi:schemaLocation">http://www.intershop.com/xml/ns/enfinity/6.1/xcs/impex catalog.xsd http://www.intershop.com/xml/ns/enfinity/6.1/core/impex-dt dt.xsd</xsl:attribute>
>              <xsl:namespace name="xsi">http://www.w3.org/2001/XMLSchema-instance</xsl:namespace>
>              <xsl:namespace name="">http://www.intershop.com/xml/ns/enfinity/6.2.2/xcs/impex</xsl:namespace>
>              <xsl:namespace name="xml">http://www.w3.org/XML/1998/namespace</xsl:namespace>
>              <xsl:namespace name="dt">http://www.intershop.com/xml/ns/enfinity/6.1/core/impex-dt</xsl:namespace>
>              <xsl:attribute name="major" select="$major"/>
>              <xsl:attribute name="minor" select="$minor"/>
>              <xsl:attribute name="family" select="$family"/>
>              <xsl:attribute name="branch" select="$branch"/>
>              <xsl:attribute name="build" select="$build"/>
>
>
> Yours,
>
> Martijn
> _______________________________________________
> oXygen-user mailing list
> 
> http://www.oxygenxml.com/mailman/listinfo/oxygen-user



More information about the oXygen-user mailing list