Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
Nine lines of code to generate “Appendix” or “Appendices”! In XSLT 2.0, that becomes
then ‘Appendix’ else ‘Appendices’”/>
Let's see how the table of contents is produced. The structure of the
element, and also of
First-level heading
Some text
Second-level heading
Some more text
Third-level heading
Lots more text
Each
element giving its section title, paragraphs of immediate content, and zero or more
and zero or more
In the
Non-normative is jargon meaning “for information only, not officially part of the specification.”
The template rule that generates an entry for a top-level section in the table of contents looks like this:
This starts by applying templates to itself with mode
divnum
; this invokes a template to calculate the section number. We'll take a look at this template rule shortly. The rule then generates an HTML
element to produce a hyperlink. The
href
attribute is generated by calling a named template
href.target
, with the current node (the
element (the displayed text that the user clicks on) is produced by applying templates to the
element, with the special mode
text
. The stylesheet doesn't actually contain a template rule for this mode; it is used simply to invoke the built-in template rule, which returns the textual content of the
element, minus any markup.
The
href.target
template looks like this:
To my mind this is crying out to be replaced by an XSLT 2.0 function, something like:
This would allow the code:
to be rewritten as:
If the global parameter
$toc.level
is greater than one, then the
toc
to generate another level in the table of contents.
The template rule for
toc
and the template rules for further levels, such as
Hexadecimal
a0
(decimal 160) is the Unicode code for the nonbreaking space character, better known to HTML authors as the entity reference
. This is not available as a built-in entity in XML. It is possible to define it as an entity in the DTD, but the authors of this stylesheet chose to write it explicitly as a numeric character reference.