XSL: The eXtensible Stylesheet Language
XSL is an XML document type that defines transformations that define how to translate one variation of XML to another, in this case taking the XForms XML data and turning it int228. The great thing about having the XSL being used from a separate file is allows you to define multiple skins, and apply them to the same form. This means that a form can change based on a user's preference, in the same way as modifying a style sheet. You can also change the actions, validations, and transformations, and customize them to the user. This enables you implement forms that are based on the same data, rendered with the same code, but provide entirely different functionality depending on the type of user who is using the page.This book doesn't have the space to define XSL in depth, but I'll describe the basics of how it works and how you can use it to create and extend the XSL that's been provided by ColdFusion MX 7 to define your own libraries.NOTE
The complete definition of XSLT can be found at http://www.w3.org/TR/xslt.XSL works by doing XPath searches, which return groups of matches called nodesets , and applying rules to them. The XSL language has three parts, XPath , the language use for referencing the various parts of an XML document, XSLT , or XSL Transformations, which is a language for describing the transformation of one XML document into another (in this case, XHTML), and XSL , the Extensible Stylesheet Language, which is XSLT plus a set of objects and properties that allow you to format the document.The XSL documents we'll be dealing with are also called XSL stylesheets; their XML document root is <xsl:stylesheet>, or sometime <xsl:transform>, which is turns out is exactly the same thing.Here's a very short example of an XSL stylesheet that converts an XML document int228.First, here's the overly simply document we want to translate:
All we want to do is convert this to a227 document, with the <italic> converted to a227 <EM> tag. This style sheet will do that:
<?xml version="1.0"?>
<italic>This is in italics</italic> and this isn't.
How does that work? Each of the <xsl:template> tags in the document match text in the document. match="italic" in the above matches the <italic> in the document, and anything that doesn't match is passed through by the <xsl:apply-templates>, which tells the system to apply any template handlers that follow this one (if you leave that out, it'll stop processing here, and it applies the templates in the order they are in the document.) Since there's no deeper templatethere aren't any more in the file at allthe default handler, which doesn't do anything at all, handles them by just passing through the text.Therefore, the output of this stylesheet applied to this XML file would be:
<?xml version='1.0'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="italic">
<EM><xsl:apply-templates/></EM>
</xsl:template>
</xsl:stylesheet>
The most important elements of XSL (as far as the ColdFusion MX 7 XSL stylesheets are concerned) and what they do are in Table 20.5. All xsl elements start with xsl.<input> tag.
<EM>This is in italics</EM> and this isn't.