[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Avoiding namespace generation in elements

Subject: Re: Avoiding namespace generation in elements
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Fri, 03 Jun 2011 08:00:45 +0100
Re:  Avoiding namespace generation in elements
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="http://www.w3.org/2001/XMLSchema" to each of the child
elements. Using exclude-default-prefixes="xs" has no effect.

Sample output:
<xs:schema targetNamespace="http://my.happydomain123.com/test/testing/1.0"
             xmlns:tt="http://my.happydonain123.com/test/testtypes/1.0"
             xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType xmlns:xs="http://www.w3.org/2001/XMLSchema" name="Testing1">
    <xs:restriction base="xs:integer"/>
</xs:simpleType>
<xs:element xmlns:xs="http://www.w3.org/2001/XMLSchema"
name="TestAgent2" type="tt:TestAgent"/>
</xs:shcema>

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
Saxonica


&lt;</xsl:value-of>xs:schema targetNamespace="<xsl:value-of
select="$ns-map/namespaces/namespace[@pim-ns=$target-namespace and
@version=$target-namespace-version]/@namespace-uri"></xsl:value-of>"
             xmlns:xs="http://www.w3.org/2001/XMLSchema"
             <xsl:for-each select="$distinct-namespaces">
                 <xsl:variable name="pim-ns" select="./text()"
as="text()"></xsl:variable>xmlns:<xsl:value-of
select="$ns-map/namespaces/namespace[@pim-ns=$pim-ns and
@version=max($ns-map/namespaces/namespace[@pim-ns=$pim-ns]/@version)]/@prefix"></xsl:value-of>="<xsl:value-of
select="$ns-map/namespaces/namespace[@pim-ns=$pim-ns and
@version=max($ns-map/namespaces/namespace[@pim-ns=$pim-ns]/@version)]/@namespace-uri"></xsl:value-of>"
             </xsl:for-each>
elementFormDefault="qualified"<xsl:value-of
disable-output-escaping="yes">&gt;</xsl:value-of>

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,
Jacobus

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.