3. Root element
An XSLT stylesheet is an XML file itself and should therefore comply with all the rules that govern the well-formedness of XML files. All the tags must be properly nested, for instance, and there should always be an XML declaration. In addition, the document can one have root element. This root element contains all the other elements in the file.
XSLT file always start with a root element named <stylesheet>
.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> </xsl:stylesheet>
The root element, <stylesheet>
, contains a reference to a so-called namespace. In the example above, you can see that there is a reference to the official W3C XSLT recommendation namespace ('http://www.w3.org/1999/XSL/Transform'). An XML namespace is a collection of elements and attributes which are identified by a Uniform Resource Identifier (URI).
Recall that XSLT is often used to transform an XML that is based on a particular DTD to an XML document that is based on another DTD. The tranformation can be, for instance, from TEI into XHTML. In such situations, name conflicts can occur if these two encoding schemes contain elements with exactly the same names.
XML namespaces provide a solution for this problem. The namespace declaration in the example above specifies that each XSLT element must be qualified by the 'xsl' prefix.
All the element names that are preceded by the xsl: prefix are thus linked to the URL http://www.w3.org/1999/XSL/Transform. As you can see, the element