Read XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition Online
Authors: Michael Kay
encoding=“UTF-8”
doctype-public=“-//W3C//DTD XHTML 1.0 Transitional//EN”
indent=“no”
doctype-system=“http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”/>
The
. Setting
indent=“no”
is sensible on a production stylesheet, because the output is much smaller. The definitions can always be changed in an overlay stylesheet, or in some cases from the command line (with Saxon, for example, by specifying
!indent=yes
).
This is a useful catchall template rule to make sure that the source document and the stylesheet are consistent with each other. In principle, validating the source document against a DTD should ensure that it contains no surprises. But in practice, DTDs change over time, and there's no way to be sure which version of the DTD was used—indeed, there's no way to be sure that the document was validated at all. So this template rule matches any element for which there is no other more specific template rule in the stylesheet. It produces a message (typically on the console) to indicate that an unexpected element was encountered, and it then copies the offending data to the result document in such a way that the start and end tags will show up visibly in the HTML (in red). This is a good way of helping document authors to notice and correct the error.
The
element is deprecated in XHTML 1.0. Perhaps the stylesheet author used it deliberately so that it would not only show up visually but would also be flagged by an XHTML validator, thus forcing the document author to fix the problem before publication.
I don't know why the stylesheet author felt uneasy about including the code to generate the
element in this template rule. Perhaps it was because the template rule for a document node is invoked when processing the root of any document tree, not only the principal source document. If the logic for creating the skeleton of the output HTML goes in the template rule for the outermost element (which in this case is called
The
The remaining rules in the stylesheet are presented in alphabetical order, by element. This is a good way of making sure that any rule can be found quickly. Unfortunately, it also has a drawback, which is that rules that work closely together (for example, the rules for formatting the front matter, or the rules for outputting syntax productions) can be widely separated in the source file. For the purposes of exposition, I've therefore regrouped them according to their logical function. The first group I will consider are the template rules that handle the general outline of the HTML output.
Creating the HTML Outline
The main template rule is evaluated when the
The code starts by generating the
element, giving it a
lang
attribute if and only if the source document defines its language in the form
. This is useful because W3C specifications are often translated into languages other than English. Documenting which language is used can help search engines and browsers designed to make web pages more accessible; for example, with audio rendition. Exceptionally, I have shown the XHTML namespace declaration on this occasion; it actually appears on the outermost literal result element in every template rule.
The next stage is to output the
element. Most of the above section is concerned with generating the document title (as it appears in the title bar of the browser window). This is a concatenation of the
(‘--’, $additional.title)[$additional.title]”/>
Note the call on the named template
css
, which we'll look at in a moment: