18.4. Rules, patterns and templates A template rule defines a mapping of parts of a source document into a result document. During XSLT processing every element, character, comment and processing instruction in an XML document is processed by some template rule. Some of them will be handled by template rules that the stylesheet writer created. Others are handled by built-in template rules that are hard-coded into every XSLT processor. Template rules consist of two parts, the pattern and the template. Be careful with the terminology: a template is not a template rule. The pattern describes which source nodes (elements, textual data strings, comments or processing instructions) should be processed by the rule. The template describes the structure to generate when nodes are found that match the pattern. In an XSLT stylesheet, a template rule is represented by an xsl:template element.[3] The pattern is the value of the xsl:template element's match attribute, and the template proper is the element's content. [3] It would have been clearer had they called it an xsl:template-rule element, but they didn't. Template rules are simple. You do not have to think about the order in which things will be processed, where data is stored or other housekeeping tasks that programming languages usually require you to look after. You just declare what you want the result to look like and the XSLT processor figures out how to make that happen. Because everything is done through declarations we say that XSL is a declarative language. |