XSLT » Elements » xsl:stylesheet

Syntax:
<xsl:stylesheet
  version="version_number"
  id="unique_id"
  exclude-result-prefixes="list"
  extension-element-prefixes="list"
>
</xsl:stylesheet>

The xsl:stylesheet element contains all other XSLT elements and delimits the start and stop of the code in an .xsl program. No other XSLT element can occur before the opening xsl:stylesheet element, nor may any other XSLT element occur after the closing xsl:stylesheet element.

A direct comparison can be made between the opening and closing <html> ... </html> tags of the HTML language, in that both the html tag and the xsl:stylesheet element serve as delimiting containers for all other members of their respective languages.
 
An important duty performed by the xsl:stylesheet element is that it must contain the XSLT namespace declaration. The purpose of the namespace declaration is to declare that the document is an XSLT stylesheet. Use the following syntax:
 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 
Older, proprietary versions of Microsoft XSLT used the following namespace:
 
xmlns:xsl="http://www.w3.org/TR/WD-xsl"
 
The xsl:stylesheet element is also commonly referred to as the root element of the stylesheet. Since it is the root, there can be no other element that is a parent to the xsl:stylesheet element. All other XSLT elements are either children, grandchildren, or further descendants. Only the following eight XSLT elements can be children:
 

  • xsl:attribute-set
  • xsl:import
  • xsl:include
  • xsl:output
  • xsl:param
  • xsl:script
  • xsl:template
  • xsl:variable

  •  
    The xsl:transform element performs the exact same purpose as the xsl:stylesheet element. These two elements may be used interchangeably. They are considered synonymous with each other.
     
    This is not a self-closing element. The separate closing element is mandatory.

    Examples

    Code:
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
    <html>
    <body>
    <xsl:for-each select="devguru_staff/programmer">
    <div>
    NAME: <xsl:value-of select="name" />
    <br />
    DOB: <xsl:value-of select="dob" />
    <br />
    AGE: <xsl:value-of select="age" />
    <br />
    ADDRESS: <xsl:value-of select="address" />
    <br />
    PHONE: <xsl:value-of select="phone" />
    <hr />
    </div>
    </xsl:for-each>
    </body>
    </html>
    </xsl:template>
    </xsl:stylesheet>
    Output:
    NAME: Bugs Bunny
    DOB: 03/21/1970
    AGE: 31
    ADDRESS: 4895 Wabbit Hole Road
    PHONE: 865-111-1111
    NAME: Daisy Duck
    DOB: 08/09/1949
    AGE: 51
    ADDRESS: 748 Golden Pond
    PHONE: 865-222-2222
    NAME: Minnie Mouse
    DOB: 04/13/1977
    AGE: 24
    ADDRESS: 4064 Cheese Factory Blvd
    PHONE: 865-333-3333
    Explanation:

    This is the code for xslt_example_stylesheet.xsl. The output has been truncated.
     
    We use the DevGuru Staff List XML file for our example with the following header:
    <?xml-stylesheet type="text/xsl" href="xslt_example_stylesheet.xsl"?>

    Language(s): XSLT

    See Also: