XSL (eXtensible Style Sheets) Elements


XSL 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 XML. All 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 is currently working on making the next generation of HTML an XML application.

XSL 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 subtree to be generated. The XSL transformation processor merges data from the XML source document with the template. By combining a set of template fragments into a style sheet, XSL can be used to perform data-driven transformations useful for highly irregular XML data and XML documents.

The Elements of XML

XSL templates are defined using a small set of XML elements.

ElementDescription
xsl:apply-templates Directs the XSL 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:element Creates an element with the specified name in the output.
xsl:eval Evaluates a script expression to generate a text string.
xsl:for-each Applies a template repeatedly to a set of nodes.
xsl:if Allows simple conditional template fragments.
xsl:otherwise Provides multiple conditional testing in conjunction with the xsl:choose and xsl:when elements.
xsl:pi Generates a processing instruction in the output.
xsl:script Defines global variables and functions for script extensions.
xsl:stylesheet The document element of a stylesheet, containing xsl:template and xsl:script elements.
xsl:template Defines a template for the desired output for nodes of a particular type and context.
xsl:value-of Inserts the value of the selected node as text.
xsl:when Provides multiple conditional testing in conjunction with the xsl:choose and xsl:otherwise elements.