RE: [xsl] matching elements by name and type to detect invalid xpaths

Subject: RE: [xsl] matching elements by name and type to detect invalid xpaths
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Mon, 6 Oct 2008 18:35:38 +0100
> Compile that with a schema-aware processor (Saxon SA in this 
> case) and you are told:
> 
> "The complex type root does not allow a child element named wrong;"
> 
> You don't even have to validate any input, because the match 
> pattern contains the type it knows that "wrong" is not a 
> child of <root>...
> fantastic :)
> 
> I think this means you can enjoy the benefits of the paths in 
> your XSLT being checked against the schema _without_ being 
> forced to validate the input each time... which is a huge benefit.
> 

Yes, it is a huge benefit, especially when you write stylesheets for complex
industry schemas that require path expressions a mile long. Three caveats:

(a) you only get this compile-time checking if you are careful to declare
your types, e.g. the types of variables and parameters, and to define match
patterns in terms of schema-element() or element(N,T).

(b) compile-time type checking is a feature of the processor, not of the
language. The other schema-aware processor doesn't do it...

(c) you DO still have to validate the input when you run the stylesheet,
because otherwise your pattern element(root, root) won't match the input.

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

Current Thread