|
We've chosen a subset of features to use in our schemas, so we do not have a set of templates that can handle all schema features. However, here's a description of our approach, which I hope may be of some use. I'm sure there are better ones out there, like http://www.idealliance.org/xmlusa/03/call/xmlpapers/03-03-04.994/.03-03-04.html .
We've handled referenced schema files by creating a node-set of all the schemas. We can then resolve an Element References, Named Types, etc by selecting from the definitions in the schemas in this node set.
At the top of the stylesheet, we define two XSLT variables: the first variable creates a result set of all the schemas, and the second contains a node set. You'll have to use your favorite equivalent of the node-set extension function. If your XSLT is working off of an instance document, you can use a xsi:schemaLocation attribute as a starting point.
<xsl:variable name="schemaSetTree">
<xsl:apply-templates select="/xs:schema" mode="resolveSchemas"/>
</xsl:variable>
<xsl:variable name="schemaSet" select="msxsl:node-set($schemaSetTree)"/>
The "resolveSchemas" mode contains a template that walks through all the tree of included and imported schemas:
<xsl:template match="xs:schema" mode="resolveSchemas">
<xsl:param name="targetNamespace" select="@targetNamespace"/>
<xs:schema targetNamespace="{$targetNamespace}">
<xsl:copy-of select="*"/>
</xs:schema>
<xsl:apply-templates select="document(xs:include/@schemaLocation)/*" mode="resolveSchemas">
<xsl:with-param name="targetNamespace" select="$targetNamespace"/>
</xsl:apply-templates>
<xsl:apply-templates select="document(xs:import/@schemaLocation)/*" mode="resolveSchemas"/>
</xsl:template>
For convenience, all included schemas are given a @targetNamespace value equal to the parent namespace-uri.
You can then use the $schemaSet variable to resolve schema definitions. For example, the complex type definition "Dog" in the namespace "uri:pets" can be found using:
$schemaSet/xs:schema[@targetNamespace='uri:pets']/xs:complexType[@name='Dog']
Yours,
Eric G.
Portland, OR
|