Patterns in XSL
By Michael Floyd
Last month I showed how you can assemble a workbench of XML tools that together will let you serve XML documents from your Web site. One of the tools on that workbench, XML Enabler, is a Java servlet that lets you map an XSL style sheet to a specific browser. This, in turn, lets you attach a style sheet to an XML document that's capable of generating HTML specific to that browser's capabilities. Imagine being able to position a DIV block and have it look the same in Microsoft Internet Explorer 5 and in Netscape Navigator 4, or to be able to render an XML document in any browser, including Lynx. The strength in delivering such documents, as you'll see, comes from the eXtensible Style Language (XSL).
There's a lot to XSL, so this month, I'd like to show how you can use patterns to locate objects within the document tree. From there, you'll be able to specify template rules that let you format these objects. Norman Walsh provides a good introduction to XSL in his article "XSL: The Extensible Style Language" (see Web Techniques, January 1999). Since I'll focus on XSL patterns, you may want to refer to this article for an overview of XSL. (Note that there have been minor changes in the syntax since this story appeared. In particular, the <xsl:process-children> element, which processes an XSL template, has been renamed <xsl:apply-templates>. Also, the article refers to the pattern attribute as the means for specifying XSL patterns. This attribute's name has been changed to match.)