XSLT can be used to manipulate, sort, and filter XML data. Many transformations will target well-formed HTML. Well-formed means that any HTML tag can be used, subject to the stricter syntax rules of XMLall start tags are paired with end tags and are nested correctly. Well-formed HTML can be displayed by the browser, or further manipulated by XML tools. The W3C currently has a recommendation for making the next generation of HTML an XML application. The W3C XHTML 1.0: The Extensible HyperText Markup Language describes some of the benefits of defining well-formed HTML. XSLT is a valuable tool for generating well-formed HTML or other XML files.
XSLT enables you to define templates for your output, into which data from the XML source is delivered. Each template defines a pattern that identifies elements in the source tree and defines the resulting output sub-tree to be generated. The XSLT transformation processor merges data from the XML source document with the template. By combining a set of template fragments into a style sheet, XSLT can be used to perform data-driven transforms useful for highly irregular XML data and XML documents.
XSLT templates are defined using a small set of XML elements, listed below and described in this reference documentation.
XSLT Elements
xsl:apply-templates | Directs the XSLT processor to find the appropriate template to apply, based on the type and context of each selected node. |
xsl:attribute | Creates an attribute node and attaches it to an output element. |
xsl:choose | Provides multiple conditional testing in conjunction with the <xsl:otherwise> and <xsl:when> elements. |
xsl:comment | Generates a comment in the output. |
xsl:copy | Copies the current node from the source to the output. |
xsl:copy-of | Inserts sub-trees and result tree fragments into the result tree. |
xsl:element | Creates an element with the specified name in the output. |
xsl:for-each | Applies a template repeatedly, applying it in turn to each node in a set. |
xsl:if | Allows simple conditional template fragments. |
xsl:include | Specifies another XSLT style sheet to include. |
xsl:number | Inserts a formatted number into the result tree. |
xsl:otherwise | Provides multiple conditional testing in conjunction with the <xsl:choose> and <xsl:when> elements. |
xsl:output | Specifies options for use in serializing the result tree. |
xsl:param | Declares a named parameter for use within an xsl:stylesheet or xsl:template. Allows specification of a default value. |
xsl:preserve-space | Preserves white space in a document. |
xsl:processing-instruction | Generates a processing instruction in the output. |
msxsl:script * | Defines global variables and functions for script extensions. |
xsl:sort | Specifies sort criteria for node lists selected by xsl:for-each or xsl:apply-templates. |
xsl:strip-space | Strips white space from a document. |
xsl:stylesheet | The document element of a style sheet, containing all other stylesheet elements. |
xsl:template | Defines a reusable template for generating the desired output for nodes of a particular type and context. |
xsl:text | Generates text in the output. |
xsl:transform | Synonym for xsl:stylesheet |
xsl:value-of | Inserts the value of the selected node as text. |
xsl:variable | Specifies a value bound in an expression. |
xsl:when | Provides multiple conditional testing in conjunction with the <xsl:choose> and <xsl:otherwise> elements. |
xsl:with-param | Passes a parameter to a template. |
* Microsoft proprietary extensions to support scripting
Browsing XML Documents in Internet Explorer 5