This is closely related to what Saxon-SA does internally when processing a schema-aware stylesheet - it analyzes the paths that are present in each template rule and checks that they are consistent with structures defined in the schema. Actually generating a schema that the paths are consistent with would not be too different.The path analysis that Saxon does to support document projection (which is then used when loading documents, to filter out the parts of the document that are reachable) is also very similar, though it only works well for XQuery, because of the difficulty of doing static matching of apply-templates calls. If you want to try grovelling in the internals of the product, you could certainly use the output of this path analysis as the basis for a schema generator. However, I'm not sure why you would want to - I would think that generating a schema from the instance document is usually more reliable.
From: Christian Mahnke [mailto:cmahnke.sub@googlemail.com]
Sent: 12 February 2009 09:49
To: xml-dev@lists.xml.org
Subject: [xml-dev] Schema fragments form style sheets?Dear all,
I hope this is the right list for my question:
Is anyone aware of attempts to generate a XML schema (or even fragments) from a XSLT style sheet?
For example:
From my point of view it should be a reasonable assumption that, if there is a template matching element X there should be a definition of the same element in the resulting schema. The same should apply to attributes as well, if the style sheet looks for attribute Y inside the template for element X, the schema fragment for X should have a attribute Y. It should even be possible to make assumptions on invalid constructs by looking for fatal XSLT message elements.
I'm aware that there are many limitations, starting with complex matching attributes of the XSLT template element and not ending with complex XPaths.
With best wishes,
Christian