Re: [xsl] XSLT Processor - root node template & version question

Subject: Re: [xsl] XSLT Processor - root node template & version question
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 10 Oct 2002 00:38:42 +0100
Hi Will,

> Q1: Does it matter (speed wise or best practice) if a template is
> defined for the root element? My understanding is that the root node
> is automatically processed first by the processor.

My practice is to match the root node but to use it purely as a
routing mechanism for directing processing off to a template matching
the document element in a particular mode. In other words, all
templates but the template matching the root node have a mode, and the
root node is just used to choose that mode:

<xsl:template match="/">
  <xsl:apply-templates mode="html" />

<xsl:template match="RouteCodeMaintLookup" mode="html">

My reasoning is that this helps maintenance because it makes it easier
to merge stylesheets together, particularly when you're merging them
to create a pipeline within the stylesheet. For example, it would be
easy to import this stylesheet and another stylesheet into a
stylesheet with a single template, matching the root node, that does
something like:

<xsl:template match="/">
  <xsl:variable name="filtered">
    <xsl:apply-templates mode="filter" />
  <xsl:apply-templates select="exsl:node-set($filtered)/*"
                       mode="html" />

It's a lot harder to merge stylesheets when the templates in them all
use the same (default) mode and when the bulk of the processing is
done in the template matching the root node.

> Q2: Since the XSLT 1.1 never made it past WD status is there any
> gain in specifying it? I use Xalan-j.

No, there's no benefit; don't specify 1.1.



Jeni Tennison

 XSL-List info and archive:

Current Thread