|Chapter 3 - Transforming with Style (Stylesheets, That Is)|
|XSLT For Dummies|
|by Richard Wagner|
|Hungry Minds 2002|
An XSLT stylesheet has a well-defined structure. Perhaps the easiest way to make sense of this structure is to compare it to something you are familiar with already, such as an ordinary document.
A document is made up of one or more paragraphs. A paragraph is a division of a document that contains one or more sentences that express a unified thought. However, not all sentences in a well-crafted paragraph are created equal. Traditionally, the first sentence holds a unique responsibility to lead the rest of the sentences by introducing a new subject or idea. The rest of the paragraph then expands upon this idea.
When you look at an XSLT stylesheet, youll find a comparable structure. At the top level is a stylesheet , which acts as the overall container for XSLT code, much like a document serves as a container for all the sentences inside it. Whereas a paragraph is the primary component of a document, a template rule is the basic building block of a stylesheet. And, like the first sentence in a paragraph, the match pattern defines where the template rule is going. Figure 3-1 highlights these layers of a stylesheet.
Figure 3-1: Structure of an XSLT stylesheet.
Taking this analogy a step further, there are some elements in a document that arent paragraphs per se. In a normal business letter, for example, the return address, date, greeting, and signature are all distinct, required elements but do not fit the definition of a paragraph. In the same way, an XSLT stylesheet has additional elements, such as xsl:output , that are valid to use but do not fit inside template rules.