RE: [xsl] Schema aware transformations

Subject: RE: [xsl] Schema aware transformations
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 22 Jun 2005 14:58:07 +0100
> Is it feasible for a schema aware processor to detect unreachable
> templates?

If they're defined by name alone, then at present no, because there's always
the possibility that the stylesheet will create an untyped temporary tree
and apply templates to it. (But there's always scope for optional warnings
that detect such situations).

To get the real benefit of schema-aware XSLT processing, you really need to
start defining match patterns in terms of schema-declared elements and
types, for example

<xsl:template match="schema-element(invoice)/delivery-address/postcode">

Once you start doing this, you get a lot more of your errors detected at
compile time, because the XSLT processor knows when analyzing the body of
the template what the types of the context node (and its children, etc) are.
For example one of my users the other day had deep within a template a call
on

my:function(current())

and got a compile-time type error because the expected type of the first
argument of my:function was not the same as the type of the match pattern. 

This kind of thing is so useful that I'm hoping in due course to add an
option that declares a stylesheet to be "fully-typed" - that is, it won't
accept any untyped data, and the compiler can then assume that any element
name in the stylesheet corresponds to an element name in the schema. (The
details aren't easy, which is why this option isn't in the spec.)
> 
> Ultimately I really want to start using SA processing but I can't find
> the justification just yet...
> 

It's a fair investment to get started (time learning the ropes, and time
establishing schemas for all your documents) but once you're over the curve,
it makes the debugging cycle a completely different experience - instead of
wrong or absent output, you get accustomed to expecting early error
messages, often at compile time.

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

Current Thread