XSLT » Elements » xsl:transform

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

The xsl:transform 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:transform element, nor may any other XSLT element occur after the closing xsl:transform 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:transform element serve as delimiting containers for all other members of their respective languages.
 
An important duty performed by the xsl:transform 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:transform 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:transform 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:stylesheet element performs the exact same purpose as the xsl:transform 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:transform 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:transform>
    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_transform.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_transform.xsl"?>

    Language(s): XSLT

    See Also: