In the domain of XSLT, the stylesheet contains a number of templates expressed as an <xsl:template> element with a match attribute. The value of the match attribute is a pattern, and the pattern determines which nodes in the source tree the template rule matches. For example: <xsl:template match="/"> Several events occur during a typical transformation. When an XSLT transformation is executed, a stylesheet is applied to evaluate and process a source document. As we discussed earlier in this chapter, the first event to take place is the remapping of the document to a tree that is contained in memory. This prepares the schema and content for the transformation process. The next step is to find a template rule that matches the root node of the source tree. Then the XSLT processor initiates the contents of the template rule, which, within the stylesheet, is a sequence of elements and text nodes. For example: <xsl:stylesheet id = id extension-element-prefixes = tokens exclude-result-prefixes = tokens version = number> <! Content: (xsl:import*, top-level-elements) > </xsl:stylesheet> <xsl:transform id = id extension-element-prefixes = tokens exclude-result-prefixes = tokens version = number> <! Content: (xsl:import*, top-level-elements) > </xsl:transform>[2]
A template rule has the following two parts:
A template can contain elements that specify literal result-element structure. A template can also contain elements from the XSLT namespace that are instructions for creating result-tree fragments. When a template is initiated, each instruction is executed and replaced by the result-tree fragment that it creates. Instructions can select and process descendant source elements. Processing a descendant element creates a result-tree fragment by finding the applicable template rule and instantiating its template. Note that elements are processed only when they have been selected by the execution of an instruction. The result tree is constructed by finding the template rule for the root node and initiating its template. |