[xsl] Generating an XSD: namespace difficulty

Subject: [xsl] Generating an XSD: namespace difficulty
From: Ben Drees <ben@xxxxxxxxxxxx>
Date: Thu, 24 Mar 2005 16:06:36 -0800
Hi,

I would like to generate XSD files from XML files using XSL, but I'm
having problems with namespaces in the result documents.

I have an XSD file that defines a simple vocabulary for describing
domain models, call it domain-model.xsd.

I have several XML files conforming to domain-model.xsd that describe
particular domain models - things like movie-domain-model.xml,
music-domain-model.xml, and so on, for example.

I have an XSL file that mostly does the right thing. The problem is that
I can't generate namespace prefixes in the XSL that come out properly in
the XSD result document.

For example, one of my result XSDs looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema";
targetNamespace="http://www.mycompany.com/movie#";
elementFormDefault="qualified" attributeFormDefault="unqualified">

<xs:element name="movie">
.
.
.
</xs:element>

<xs:simpleType name="id">
  <xs:restriction base="xs:string"/>
</xs:simpleType>

<xs:simpleType name="markup">
  <xs:restriction base="xs:string"/>
</xs:simpleType>

<xs:complexType name="notes">
  <xs:sequence>
    <xs:element name="id" type="id"/>
    <xs:element name="display-name" type="markup"/>
    .
    .
    .
  </xs:sequence>
</xs:complexType>

The targetNamespace attribute in the xs:schema element causes the
simpleTypes named "id" and "markup" to be created in the
"http://www.mycompany.com/movie#"; namespace, right? So then when these
types are referred to by elements in the "notes" complexType below, they
need a namespace prefix like "mov" for
"http://www.mycompany.com/movie#";.

I can't figure out how to get the declaration of such a prefix into the
xs:schema result element since both the prefix and the URI to which it
refers are unknown until runtime.

I've found some information on generating XSL from XSL, the
namespace-alias element, and the fact that namespace nodes are different
than attribute nodes, which have all been helpful. But I'm still not
quite sure if what I'm trying to do is possible.

-Ben

Current Thread