The Ground Cero Guide to XSL
Henrik Aasted Sorensen
<< Introducing the Extensible Stylesheet Language (XSL)Basic XSLT >>
4. XSLT
Namespaces
One of the first issues to address when working with XSLT is how to mix XML-languages. Imagine if the address-language from the above example contained a tag called <br>. It might cause a bit of trouble if we wanted to transform an address-document containing that tag into an XHTML-document, because XHTML contains a tag with the same name. To resolve this conflict, namespaces were introduced. Namespaces allow a document to contain tags from several different XML-languages.
Namespaces are defined in the root-tag of the document. A namespace is defined as:
<roottag xmlns:ns="URI">
xmlns: is the keyword indicating that we're registering a namespace. ns is a short name for the name-space, while the URI (Universal Resource Identifiers) is used to uniquely identify the XML-language used. URIs take the form of an ordinary web-address. This is done to avoid collisions in URIs. Anyone making a new XML-language should choose an URI from their own domain-address. The address doesn't necessarily need to point to anything, but it's convenient to let it point to the specification of the language. The XSLT-URI is "http://www.w3.org/1999/XSL/Transform" and the XHTML-URI is "http://www.w3.org/1999/xhtml". Namespaces are used by putting the short name or the entire URI in front of each tag.
Example. The person-tag, if its namespace is called add, would look like:
<add:person name="John Doe"> ... </add:person>
Example of specifying namespaces for a document:
<add:addresses xmlns:add="http://www.phonedirectoy.org/XML" 
     xmlns="http://www.w3.org/1999/xhtml">
Notice that a short name for the XHTML-namespace is not defined. This makes it the default namespace. Any tags in the document without a namespace will then be considered a XHTML-tag.
<< Introducing the Extensible Stylesheet Language (XSL)Basic XSLT >>
Index