How Does XSL Work
Added 26 Jul 2008
Before discussing XSL in more detail, it's necessary to consider the XSL processing model. An XSL processor begins with a style sheet and a "source tree." The source tree is the tree representation of the parsed XML source document. All XML documents can be represented as trees.
Conceptually, the XSL processor begins at the root node in the source tree and processes it by finding the template in the style sheet that describes how that element should be displayed. Each node is then processed in turn until there are no more nodes left to be processed. (In fact, it's a little more complicated than this because each template can specify which nodes to process, so some nodes may be processed more than once and some may not be processed at all. We'll examine this later.)
The product of all this processing is a "result tree." If the result tree
is composed of XSL formatting objects, then it describes how to present the
source document. It's a feature of XSL that the result tree doesn't have to
be composed of XSL formatting objects–it can be composed of any elements.
One common alternative to XSL formatting objects will be HTML element names.
When HTML is used in the result tree, XSL will transform an XML source document
into an XML document that looks very much like HTML. It's important to realize,
however, that the result is XML, not HTML. In particular, empty elements will
use the XML empty-element syntax, and it's impossible to produce documents
that are not well-formed XML.