W3C home > Mailing lists > Public > www-style@w3.org > September 1999

Re: XSLT: processing sequence/flow control

From: Michael Fuller <msf@mds.rmit.edu.au>
Date: Sat, 11 Sep 1999 12:36:42 +1000
To: Wim de Vries <w.vries@elsevier.nl>
Cc: www-style@w3.org
Message-ID: <19990911123642.A5715@io.mds.rmit.edu.au>
First, an aside. Questions like this are best directed to the
XSL-List mailing list at http://www.mulberrytech.com/xsl/xsl-list/
Subscription is open; the list is archived.

On Fri, Sep 10, 1999 Wim de Vries asks:
> I can not find an answer in the XSLT draft document about the processing
> sequence of source tree and a XSL style sheet. Is it data/message driven?
> Or are the template rules executed successively? Or mixed?

It's mixed. The data determines which templates apply; templates then
recursively direct direct what data to process.

> So, now where does the processors starts:
> - at the XML doc, identifying <book> and selecting template 1 and
> successively the same for the childs. [...]
> - at the stylesheet, executing the first template it encounters. [...]
> Can some help me out here?

What you're missing is section 5.8 of the XSLT draft: Built-in templates.
An XSLT engine must supply certain default templates to apply in the
absence of an explicit template rule, including**:
    <xsl:template match="*|/"><xsl:apply-templates/><xsl:/template>

Processing involves matching nodes from the source tree against template
patterns; the template with the (best) matching pattern is then
instantiated to form part of the result tree.

In your example:
> XML:
> <book>
>  <title>Johns Book</title>
>  <author>
>   <first-name>John</first-name>
>   <surname>the Writer</surname>
>  </author>
> </book>
> XSL:
> <xsl:template match="book">	//template 1
>  <fo:inline-sequence font-weight="bold">
>    <xsl:apply-templates/>
>  </fo:inline-sequence>
> </xsl:template>
> <xsl:template match="surname">	//template 2
>  <fo:inline-sequence font-weight="italic">
>    <xsl:apply-templates/>
>  </fo:inline-sequence>
> </xsl:template>
> <xsl:template match="first-name">	//template 3
>  <fo:inline-sequence font-weight="italic">
>    <xsl:apply-templates/>
>  </fo:inline-sequence>
> </xsl:template>

 ...processing would start by matching the above built-in template
to the root node of the source tree; instantiating that template
selects the child nodes of the root for recursive processing.

The first child node of root of the source tree is the <book>...</book>
element; this is matched by your template 1. Instantiating template 1
causes the literal "<fo:inline-sequence font-weight="bold">" to be added
to the result tree; the child nodes of "<book>...<book>" are then selected
for processing. Etc, etc. Eventually, the recursive processing of those
children is completed, and the literal "</fo:inline-sequence>" is emitted,
completing the result tree.

For a nice, up-to-date introduction to XSLT, see chapter 14 of
Elliote Rusty Harold's _The XML Bible_, available on line at:

The best way of getting to understand all this is to install XT,
James Clark's stand-alone Java implementation of XSLT:

Hope this all helps.

Michael Fuller

** the others are:
    <xsl:template match="text()|@*"><xsl:value-of select="."/><xsl:/template>
    <xsl:template match="processing-instruction()|comment()"><xsl:/template>
Multimedia Databases Systems,                  Phone:      +61 3 9925 4148
RMIT University                                Fax:        +61 3 9925 4098
Level 3, 110 Victoria St,                          msf@mds.rmit.edu.au
Carlton 3053, Australia.                    http://www.mds.rmit.edu.au/~msf/
Received on Friday, 10 September 1999 22:37:00 UTC

This archive was generated by hypermail 2.3.1 : Monday, 2 May 2016 14:26:51 UTC