xsd element vs literal text ... why the difference

W

wooks

<?xml version="1.0" ?>
- <xsd:schema targetNamespace="urn:faster:userlogin"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="urn:faster:userlogin">
<xsd:include schemaLocation="C:\Faster\App\Demo\DataTypes\login.xsd"
/>
<xsd:include schemaLocation="C:\Faster\App\Demo\DataTypes\password.xsd"
/>
- <xsd:complexType name="userloginType">
- <xsd:all>
<xsd:element name="login" type="login" />
<xsd:element name="password" type="password" />
</xsd:all>
</xsd:complexType>
<xsd:element name="userlogin" type="userloginType" />
</xsd:schema>

The above schema was produced by the following stylesheet. Note the
default namespace is only defined once. Here is the stylesheet

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="urn:~app~:dummy"
version="1.0">
<xsl:eek:utput method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>

<xsl:template match="/">
<xsd:schema>
<xsl:attribute
name="targetNamespace">urn:~app~:dummy</xsl:attribute>
<xsl:apply-templates select="files/file" mode="include"/>
<xsd:complexType name="dummyType">
<xsd:all>
<xsl:apply-templates select="files/file" mode="complexType"/>
</xsd:all>
</xsd:complexType>
<xsd:element name="dummy" type="dummyType"/>
</xsd:schema>
</xsl:template>

<xsl:template match ="files/file" mode="include">
<xsd:include schemaLocation = "{.}"/>
</xsl:template>
<xsl:template match ="files/file" mode="complexType">
<xsd:element name = "{.}" type="{.}"/>
</xsl:template>
</xsl:stylesheet>

Now by changing the xsd:schema in the stylesheet to xsl:element
name="xsd:schema" I get an equivalent but different result with the
default namespace being defined multiple times.

So this

<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="urn:~app~:dummy"
version="1.0">
<xsl:eek:utput method="xml" version="1.0" encoding="UTF-8"
indent="yes"/>

<xsl:template match="/">
<xsl:element name="xsd:schema">
<xsl:attribute
name="targetNamespace">urn:~app~:dummy</xsl:attribute>
<xsl:apply-templates select="files/file" mode="include"/>
<xsd:complexType name="dummyType">
<xsd:all>
<xsl:apply-templates select="files/file" mode="complexType"/>
</xsd:all>
</xsd:complexType>
<xsd:element name="dummy" type="dummyType"/>
</xsl:element>
</xsl:template>

<xsl:template match ="files/file" mode="include">
<xsd:include schemaLocation = "{.}"/>
</xsl:template>
<xsl:template match ="files/file" mode="complexType">
<xsd:element name = "{.}" type="{.}"/>
</xsl:template>
</xsl:stylesheet>

produces this schema


<?xml version="1.0"?>
<xsd:schema targetNamespace="urn:faster:userlogin"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:include schemaLocation="C:\Faster\App\Demo\DataTypes\login.xsd"
xmlns="urn:faster:userlogin" />
<xsd:include schemaLocation="C:\Faster\App\Demo\DataTypes\password.xsd"
xmlns="urn:faster:userlogin" />
<xsd:complexType name="userloginType" xmlns="urn:faster:userlogin">
<xsd:all>
<xsd:element name='login' type='login' />
<xsd:element name='password' type='password' />
</xsd:all>
</xsd:complexType>
<xsd:element name="userlogin" type="userloginType"
xmlns="urn:faster:userlogin" />
</xsd:schema>

which has urn:faster:userlogin namespace defined 4 times.

Although they are equivalent why the difference...

PS the ~app~ in the stylesheets get replaced by a script before the
schema is produced.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top