With a schema-aware stylesheet, provided you include enough type information in your code, Saxon will give you warning messages where it can infer that a path is "invalid" in the sense that it will never select anything (I sometimes refer to these as "void" paths - they are legal, but essentially useless, rather like writing $x+0).
 
Saxon's type-checking in XSLT is essentially at the level of a template rule. So if the type of the matched element is known, everything selected downwards from there will be checked. For example if you write
 
<xsl:import-schema namespace=http://some/namespace schema-location="abc.xsd"/>
 
<xsl:template match="schema-element(foo)">
  <xsl:for-each select="bar">
     <xsl:value-of select="baz"/>
 
then Saxon will tell you if a foo/bar element cannot contain a baz element.
 
This won't work if you don't import a schema, and it won't work if you simply say match="foo", because that will match any element named foo whether or not it is a valid instance of the element declaration foo in the schema. (I'm thinking of introducing a diagnostic mode in which you can get warnings even if you only said match="foo", but it's not there yet).
 
The other thing to be aware of is that if you write your stylesheets like this, the source document presented to the stylesheet must be validated against the schema.
 
If you're concerned with performance, the effect is mixed: the transformation will generally run faster, but sometimes the speed-up is not enough to compensate for the extra cost of doing schema validation on the input.
 
Schema-aware processing is only available with Saxon Enterprise Edition.
 

Regards,

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

 
 


From: Marcin Ochocki [mailto:ochocki@gmail.com]
Sent: 16 December 2009 13:28
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Veryfing XPath expressions inside XSTL document

Hi,

I would like to continue thread from here: http://groups.google.pl/group/microsoft.public.xsl/browse_thread/thread/640a3889d78ab3a1.

In short:
I want to werify that XPath expressions in my xslt documents are valid. Now, with SaxonHE when I exectute following command:
saxonhe9-2-0-3n\bin>transform -s:PDFGenerator.xml -xsl:PDFGenerator.xslt

There is no error (in PDFGenerator.xslt I put XPath expression with fileld that does not exist in xml)

Can Saxon detect such a situation?

Regards,
Marcin