Re: [xsl] Avoiding namespace generation in elements

Subject: Re: [xsl] Avoiding namespace generation in elements
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Fri, 03 Jun 2011 08:00:45 +0100
On 02/06/2011 18:29, Jacobus Reyneke wrote:
Good day,

I am transforming a XML file to XSD using Saxon and XSLT 2.0

I am manually creating the 'schema' element, since I am adding
namespaces to it. This causes Saxon in add
xmlns:xs=""; to each of the child
elements. Using exclude-default-prefixes="xs" has no effect.

Sample output:
<xs:schema targetNamespace="";
<xs:simpleType xmlns:xs=""; name="Testing1">
    <xs:restriction base="xs:integer"/>
<xs:element xmlns:xs="";
name="TestAgent2" type="tt:TestAgent"/>

Crappy way of creating main schema that is causing the headache:
<xsl:value-of disable-output-escaping="yes">

Using d-o-e has many disadvantages, but I hadn't come across this one before! There's absolutely no need for this clumsy workaround. Use xsl:namespace to create the "dynamic" namespaces, and all will be well.

Michael Kay

&lt;</xsl:value-of>xs:schema targetNamespace="<xsl:value-of
select="$ns-map/namespaces/namespace[@pim-ns=$target-namespace and
             <xsl:for-each select="$distinct-namespaces">
                 <xsl:variable name="pim-ns" select="./text()"
select="$ns-map/namespaces/namespace[@pim-ns=$pim-ns and
select="$ns-map/namespaces/namespace[@pim-ns=$pim-ns and

As you can see, I am creating namespace attributes on the fly, which
is why I can't just add<xs:schama>  as part of my xslt.

Kind regards,

Current Thread