ELEMENT:  xsl:transform

<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.
     
    version="version_number"
     
    The mandatory version attribute is set to the version number. Currently, the version number is "1.0".
     
    id="unique_id"
     
    The optional id attribute is a unique identifier for the stylesheet. This allows the stylesheet to be referenced in another XML document.
     
    exclude-result-prefixes="list"
     
    The optional exclude-result-prefixes attribute is a list, delimited by white-space, of the namespaces prefixes that should not be copied into the output (the result tree).
     
    extension-element-prefixes="list"
     
    The optional extension-element-prefixes attribute is a list, delimited by white-space, of the namespaces prefixes used for extension elements.
     
    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"?>
    and we name it: xslt_example_transform.xml
     
    Code for xslt_example_transform.xsl:
     
    <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:
     
    Click to view output in separate window - requires Internet Explorer

     
    Copyright 1999-2001 by Infinite Software Solutions, Inc. All rights reserved.
    Trademark Information