Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
If the selected template rule is a built-in rule, then any parameters that are supplied are passed on to any template rules called by the built-in rule, in the same way that the mode is passed on. This is a change from XSLT 1.0. For example, consider:
…
When a
$in-section
will of course take the value
true
as expected. If there is an intervening element, with no explicit template rule, so that the
$in-section
will still have the value
true
. The reason is that the built-in template rule for the intermediate element calls
Result
The result of evaluating the
This doesn't mean that the XSLT processor has to process the nodes sequentially. It can process them in any order it likes, or in parallel, as long as it assembles the results in the right order at the end.
Usually,
…
match=“xsl:analyze-string | xsl:for-each-group |
xsl:character-map | xsl:next-match | …”>
In this example, the result returned by
Note that it's quite legitimate to use
In this situation the context node is taken as the root of the principal source document, so the
circularity
.
Usage and Examples
First, some simple examples are given below.
Construct | Effect |
Processes all the children of the context node | |
Processes all the | |
Processes every element in the document in mode toc | |
Process all the indent parameter in each called template to the value of the variable $n plus 4 | |
Process all the isbn attribute |
The following sections give some hints and tips about using
rule-based
design pattern: the definition of each individual template rule declares which nodes it is interested in, rather than the template rule for the parent node defining in detail how each of its children should be processed. The rule-based approach works particularly well when the document design is likely to evolve over time. As new child elements are added, template rules to process them can also be added, without changing the logic for the parent elements in which they might appear.
This style of processing is sometimes called
push
processing. It will be familiar if you have used text-processing languages such as awk or Perl, but it may be unfamiliar if you are more used to procedural programming in C++ or Visual Basic.
Where the structure is more regular and predictable, it may be simpler to navigate around the document using
pull
processing. The
SELECT
statement in SQL.
A unique strength of XSLT is the ability to mix these two styles of programming. I'll discuss both approaches, and their relative merits, in more detail in Chapter 17.
Modes
Modes are useful where the same data is to be processed more than once.
A classic example is when building a table of contents. The main body of the output can be produced by processing the nodes in default mode, while the table of contents is produced by processing the same nodes with
mode=“TOC”
.