I have a number of xml schema documents which are used to describe configuration settings for my application. The xml schemas look something along the following lines:
Client.xsd
<xsd:schema targetNamespace="http://www.example.com/network"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="Client">
<xsd:attribute name="Host" type="xsd:string>
</xsd:complexType>
</xsd:schema>
Server.xsd
<xsd:schema targetNamespace="http://www.example.com/network"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="Server">
<xsd:attribute name="Port" type="xsd:unsignedShort>
<xsd:attribute name="MaxConnections" type="xsd:int default="32">
</xsd:complexType>
</xsd:schema>
Application.xsd
<xsd:schema targetNamespace="http://www.example.com/core"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:complexType name="Application">
<xsd:attribute name="Name" type="xsd:string>
<xsd:attribute name="Id" type="xsd:int>
</xsd:complexType>
</xsd:schema>
FooClient.xsd
<xsd:schema targetNamespace="http://www.example.com/foo"
xmlns:core="network://www.example.com/network"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.example.com/network"
schemaLocation="client.xsd"/>
<xsd:complexType name="FooClient">
<xsd:complexContent>
<xsd:extension base="network:Client">
<xsd:attribute name="foo" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
FooServer.xsd
<xsd:schema targetNamespace="http://www.example.com/foo"
xmlns:core="network://www.example.com/network"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.example.com/network"
schemaLocation="client.xsd"/>
<xsd:complexType name="FooServer">
<xsd:complexContent>
<xsd:extension base="network:Server">
<xsd:attribute name="foo" type="xsd:string"/>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
</xsd:schema>
FooApplication.xsd
<xsd:schema targetNamespace="http://www.example.com/foo"
xmlns:core="http://www.example.com/core"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<xsd:import namespace="http://www.example.com/core"
schemaLocation="Application.xsd"/>
<xsd:include schemaLocation="FooClient.xsd"/>
<xsd:include schemaLocation="FooServer.xsd"/>
<xsd:complexType name="FooApplication">
<xsd:complexContent>
<xsd:extension base="core:Application">
<xsd:sequence>
<xsd:element name="FooInput" type="FooClient"/>
<xsd:element name="FooOutput" type="FooServer"/>
</xsd:sequence>
</xsd:extension>
</xsd:complexContent>
</xsd:complexType>
<xsd:element name="Foo" type="FooApplication"/>
</xsd:schema>
This is an example of an instance document:
<foo:Foo xmlns:foo="http://www.example.com/foo"
Id="1234"
Name="FooInstance1">
<FooInput Host="localhost:12345"
Name="Input"
foo="bar"/>
<FooOutput Port="54321"
Name="Output"
foo="bar"/>
</foo:Foo>
My aim is to take the FooApplication schema document and turn it into a human readable form so that the people responsible for maintaining the application know exactly what configuration options are available, the data types, default values etc. Eventually I will add documentation elements which can also be added to the output, but for now I'm trying to keep it simple. So the example above could look something like this:
FooApplication/Id, int
FooApplication/Name, string
FooApplication/FooInput/Host, string
FooApplication/FooInput/foo, string
FooApplication/FooOutput/Port, unsignedShort
FooApplication/FooOutput/MaxConnections, int, default=32
FooApplication/FooOutput/foo, string
For this task xslt seems like the obvious tool. However I'm having a hard time getting my head around how to pull in data from the multiple documents. I tried something like this (for example for indexing all elements of complexType):
<xsl:template match="xsd:include">
<xsl:apply-templates select="document(@schemaLocation)"/>
</xsl:template>
<xsl:template match="xsd:import">
<xsl:apply-templates select="document(@schemaLocation)"/>
</xsl:template>
<xsl:key name="complexType" match="xsd:complexType" use="@name"/>
However when using the key, only the complexType from FooApplicaiton.xsd is resolved.
Does anyone have any insights into how this could be achieved?
Many thanks in advance.