RE: [xsl] Compact XPath syntax

Subject: RE: [xsl] Compact XPath syntax
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Thu, 20 Dec 2007 00:39:35 -0000
> //c  seems to be what you are looking for.
> In XSLT2, with a schema aware processor, in some limited 
> situations, you may be able to use knowledge of a schema to 
> make such optimsations but in general this is not possible.

Saxon-SA will rewrite //c as /a/b/c provided that the type of the context
node is statically known. It is generally good practice to declare type
information when writing schema-aware stylesheets, for example

<xsl:template match="document-node(schema-element(fpml:FPML))">
  <xsl:value-of select="//x"/>

The type information can be used both for optimization and for better error
checking: with a complex schema like FPML, it's very useful to be able to
abbreviate your path expressions (which can otherwise be immensely long)
without incurring any performance penalty.

Michael Kay

Current Thread