XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (713 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
12.02Mb size Format: txt, pdf, ePub

There's a great deal of clutter in this rule. The code outputs a table row (a

element) and the first three cells in that table (

elements).

For each

element, there is a six-line

instruction that is concerned solely with coloring change-marked sections in the code: changes from one version to the next are marked by the presence of a
diff
attribute on this or some ancestor element, and the coloring happens only if the stylesheet parameter
$show.diff.markup
is enabled. This clutter could be reduced dramatically by replacing the six lines with a call such as the following, to return the relevant attribute node when required, or an empty sequence otherwise:


The first cell contains an optional hyperlink anchor and a sequence number. The call on

using
level=“any”
is a good example of how to generate a sequence of numbers that runs through the document. It creates a sequential number for each

element, that is, for each production rule. (Unfortunately, it is actually commented out in the current version of the stylesheet, supposedly because of a bug in one particular XSLT processor, and a less convenient technique is used instead. I decided on this occasion to publish the code as the author would have wanted it to be.)

In the second cell, the template calls

to process the contents of the

element, which will generally just be the name of the syntactic term being defined. In the third cell it outputs the
::=
that separates the term from its definition. In various places it inserts nonbreaking space characters (
 
) to achieve visual separation between the parts of the rule.

After producing these three cells, the template calls:


This selects the immediately following sibling element, provided it is an

element, and applies the appropriate template rule. Actually, I think the

element is always followed immediately by an

element, so this could have been written rather more straightforwardly as:


As I mentioned before, I would normally write the predicate as
[self::rhs]
rather than
[name()=‘rhs']
to avoid namespace problems, and more particularly, to allow the optimizer to use indexes if it can.

Other books

The Man Who Loved Dogs by Leonardo Padura
The Man Who Sold Mars by K. Anderson Yancy
Fearless by Cornelia Funke
Seeds of Deception by Sheila Connolly
cosmicshifts by Crymsyn Hart
Hard Corps by Claire Thompson
Undertow by Conway, K