why an XSL processor might skip parts of the source tree (was RE: xsl whitespace question)

Subject: why an XSL processor might skip parts of the source tree (was RE: xsl whitespace question)
From: Mike Brown <mbrown@xxxxxxxxxxxxx>
Date: Tue, 9 Nov 1999 18:38:47 -0700
Franz Figl wrote:
> I use a xsl renderer from CUESoft (In Delphi).

Okay, I see on their web page that their processor is conformant to the Dec
1998 working draft. This can be important to know. When asking a question on
the list, always mention what software you're using and what version of the
specs it implements. It can affect the answers to your questions. :)

> The "select" was my mistake. It it ok now, but
> all my other groups are gone, only the Absatz tag
> is visible. Where the are now? [...]
> 
> <xsl:stylesheet
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
> xmlns:fo="http://www.w3.org/1999/XSL/Format";>
> 
> <xsl:import href="avgesetz.xsl"/>
> <xsl:import href="3b2.xsl"/>

I can't say for certain without knowing what is in those templates.

Perhaps the following information will help.

An XML document represents a hierarchy of nodes -- the "source tree". There
are nodes of different types (elements, attributes, text, etc) and many of
these nodes are identifiable by names.

An XSL document is mainly just a collection of independent templates. Each
template "matches" a set of nodes that pass a certain test. Given any node,
you can find a template that best matches that node. There is a set of
built-in default templates that match each type of node, so there will never
be a situation where a template cannot be found that matches a node.

An XSL processor does the following:

	1. It identifies a set of nodes to process. 
         Initially, this is just the root node of the
         source tree.

	2. It looks at each node in the set, in document
	   order, and finds the template that best matches
	   each node.

	3. It executes the instructions in each template.
	   The instructions can either say to create some
	   nodes in the result tree, or they can help the
	   XSL processor make decisions about what to do
	   next (e.g. choose/when conditional blocks).

	4. When it is done executing the instructions in
	   the template for every node in the set, the
	   processing is finished.

Some templates may contain an <xsl:apply-templates/> instruction. When this
instruction is executed, a new set of nodes to process is identified and the
processor again goes to step #1. The new set of nodes to process is
identified by the select="..." attribute, or is assumed to be all child
nodes of the node currently being processed. When this set has been
processed, the instructions that followed the <xsl:apply-templates> are
executed. This is how recursive processing occurs. The XSL processor does
not automatically descend the source tree; templates tell it where to go
next.

The built-in templates are described in
http://www.w3.org/TR/xslt#built-in-rule. The default template for a text
node is to add a copy of that text node to the result tree. The default
template for any element node or the root node is simply an
<xsl:apply-templates/> instruction. The effect of this is that an XSL
processor will by default descend through the elements in the source tree,
doing nothing but adding text nodes to the result tree, from which the
output will (may, rather) be derived.

When you create a template that matches element nodes of a particular name,
this template will be chosen instead of the default template. This is what
you have done with these two templates that match element nodes named Absatz
and Nummer, individually:

> <xsl:template match="Absatz">
>  <fo:block font-family="Times" font-size="12.00pt" color="green"
> text-align="justify">
> <xsl:apply-templates select="Absatz.AZ"/>
>  <xsl:text> </xsl:text>
>  <xsl:apply-templates select="Absatz.Satz"/>
>  </fo:block>
>  </xsl:template>
> 
> <xsl:template match="Nummer">
> <fo:block font-family="Times" font-size="12.00pt" color="blue"
> text-align="justify">
> <xsl:apply-templates select="Nummer.AZ"/>
>  <xsl:text> </xsl:text>
>  <xsl:apply-templates select="Nummer.Satz"/>
>   </fo:block>
> </xsl:template>

So, the built-in templates will allow the XSL processor to go down the
source tree, copying text nodes along the way, until it gets to any Absatz
or Nummer elements. For these nodes, the processor will use the templates
you wrote. In those templates, you have instructions like this:

<xsl:apply-templates select="Absatz.AZ"/>

You are saying, "for each node in the set identified by the XPath expression
'Absatz.AZ' (relative to the current node, element children named
'Absatz.AZ') go find the template that best matches the node and execute the
instructions in that template."

If the XSL processor is skipping parts of the source tree, or is not
executing the templates you expected, it is probably because you are trying
to rely on the behavior of built-in templates that your explicit templates
now override.

Does this help?

-Mike


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread