[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] XML Schema 1.0 files

Subject: Re: [xsl] XML Schema 1.0 files
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Wed, 27 Mar 2013 22:54:23 +0000

In general, extracting information from schema documents using XSLT is difficult, unless you are prepared to make assumptions and approximations - for example, you might be prepared to ignore the impact of xs:redefine, or the risk of finding xs:element declarations within an xs:documentation element.

In this case I think you can get a reasonable answer fairly easily. If you find an <xs:element name="N"> then the namespace in question is one of the following:

(a) if parent::xs:schema then ../@targetNamespace if present, else ""

(b) otherwise, if normalize-space(@form)="qualified" or empty(@form) and normalize-space(ancestor::xs:schema/@elementFormDefault)="qualified", then ancestor::xs:schema/@targetNamespace if present, else ""

(c) otherwise, ""

I think this caters for most possibilities; an exception is chameleon include where the declarations in a schema document acquire the target namespace of the including schema document.

Michael Kay

On 27/03/2013 10:14, davep wrote:
Given an XML schema, I want to find files containing definitions & references of a particular element

Root is

<xsd:schema xmlns="http://www.x"

Later I see

<xsd:element ref="X"/>


<xsd:element name="X">
but also
<xsd:element ref="dc:X"/>

I'm looking for some xslt 2.0 that will combine
them to search for element X definitions and references
and report their namespace.
I'm working on a directory, so I'll be using collection() but
for one file all I want to know is
if element X (ref or def) is in the file, and if so, what the appropriate namespace is.
So the stylesheet parameters are the localname and the
returned value either nothing (not found) or the namespace in which the
element is, indicating it was found?
AFAICT in the above example, the namespace is /xsd:schema/@targetNamespace

Has anyone done this before please?



Current Thread