xsl-list
[Top] [All Lists]

RE: an elements schema context via xslt

2005-06-30 15:58:37
I wonder if it is possible (with a reasonable amount of code) to find
out (given a xml document, the xpath to an element in this doc and the
schema (xsd) document upon which the document is/was created), to find
out which are the possible child- (and sibling- and attribute-)
elements for the given element - using xslt.

If you read the schema spec, you will see that there's a significant amount
of work a schema processor has to do to build a schema (= a set of type
definitions) from a schema document (an xs:schema element in a source XML
document). You don't want to try writing this code yourself in XSLT. For
example, you would have to analyze model groups, attribute groups, and
substitition groups, all recursively, you would have to understand schema
imports and namespaces, wildcards, subtypes derived by extension, and a host
of other things.

(Incidentally, some schema-aware XML editors clearly don't do this very
well.)

Your better bet is to access a compiled schema using extension functions. It
shouldn't be too difficult to do this using Saxon-SA.

Also, having a path expression that identifies an element doesn't make it
especially easy to work out which element declaration or type definition is
applicable to that element. A schema-aware processor will validate the
source document and annotate each node with a reference to the schema type
that was used to validate it: with some use of extension functions, you can
get from this type annotation to the definition of the schema type in the
compiled schema, and from this to the list of permitted children.

Michael Kay
http://www.saxonica.com/



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>