To declare a namespace, set the xmlns
attribute on an element. For example:
<xsl:stylesheet version="1.0"xmlns:xsl
="http://www.w3.org/1999/XSL/Transform"xmlns
="http://www.w3.org/TR/REC-html40" >
The <stylesheet>
element declares an XSLT style sheet that will reference elements defined in the XSLT 1.0 and HTML namespaces. The XSLT elements will use an xsl
prefix for the names. The HTML elements, on the other hand, will have no prefixes in their names. The namespace declarations apply to the element and all its children.
Declaring a namespace means choosing a namespace prefix, and binding the prefix to the appropriate namespace URI. When declaring namespaces, remember the following:
xsl:
prefix. It could use something like xslt:
, transform:
, or XSLT_Stylesheet_Prefix:
, instead.
Note Not all URIs take the form of a traditional Uniform Resource Locator (URL), such as http://www.mycompany.com. In the case of the MSXML processor, in particular, Microsoft extensions to the XSLT standard, such as the msxsl:node-set()
function, are identified by a prefix associated with the URI urn:schemas-microsoft-com:xslt. The following namespace declaration is an example.
xmlns:msxsl="
urn:schemas-microsoft-com:xslt
"
This URI form is called a Uniform Resource Name (URN). Again, whether the URI takes the form of a locator or a name, the specific URI cannot be changed if you want to take advantage of a feature supported by a particular processor.