Template Rules
The basic XSL style sheet building block is a template rule. A template rule describes how an XML element node (that element and all the elements it contains) is converted into an XSL element node that can be rendered. Don't forget that you can construct new trees out of parts of the document tree (discussed on Day 19, "Converting XML with DSSSL"). The element node could be a whole branch of the document tree, or it could even be the whole of the XML document processed in a different way (for example, when creating a table of contents).
A template rule consists of two parts:
- 1. A pattern that identifies the XML node (element) in the XML document.
- 2. An action (rendering or processing part) that details the transformation and rendering of the resulting node (the element or elements that you have identified).
If all you wanted to do was pass the XML document through untouched, the following would probably be enough, although another instruction (xsl:copy) that you will learn later in this chapter can be used to pass XML code through or even to make a hybrid XML/HTML mix:
<xsl:template match="/">
<fo:page-sequence>
<xsl:apply-templates/>
</fo:page-sequence>
</xsl:template>
|
|
It is often useful to put all the basic style properties on the root of the document so that all the descendant elements inherit the properties. This is done by using a single forward slash to represent the root element:
<xsl:template match= "/">
There are many ways of matching elements, including:
- • Matching by ID
- • Matching by element name
- • Matching by ancestry
- • Matching by children
- • Matching by attributes