Re: [xsl] using XSLT to replace @ref in XML schema

Subject: Re: [xsl] using XSLT to replace @ref in XML schema
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Thu, 07 Oct 2010 09:52:06 +0100
Inspired by an issue on another list (JAXB), I'd like to ask whether
someone here has ever seen or heard about an XSLT replacing all the
@ref by their respective target?

AFAIK, they are just shortcuts, and such a replacement shouldn't make
any difference.  Also, an XSLT would be a simple way of doing this -
or am I missing something?


I think I would first build a "grand schema" document by finding the transitive closure of all the includes/imports and expanding the document-level defaults such as targetNamespace, blockDefault, elementFormDefault etc into the individual components. Then define a key on the unique name of the component - concatenation of symbol space, target namespace, and local name. Then your transformation can find the @ref attributes (and similar, e.g. @type, @itemType), construct the composite key, and use the key() function to find the component in this "grand schema".


That still leaves you a few problems, however. For example, it simply isn't possible in XSD to move a referenced component inline if it is in a different target namespace. So perhaps you only want to move element and attribute declarations inline if they are in the same namespace - perhaps in the same schema document even - in which case it becomes much simpler because they all have the same document-level defaults.

Michael Kay
Saxonica

Current Thread