Next / Previous / Contents / Shipman's homepage

4.2. The syntax of multi-namespace documents

An XML document's external form uses namespace prefixes to distinguish names from different namespaces. Each prefix's NSURI must be defined within the document, except for the blank namespace if there is one.

Here is a small fragment to give you the general idea:

<fo:inline font-style='italic' font-family='sans-serif'>
  <xsl:copy-of select="$content"/>
</fo:inline>

The inline element is in the XSL-FO namespace, which in this document uses the namespace prefix “fo:”. The copy-of element is in the XSLT namespace, whose prefix is “xsl:”.

Within your document, you must define the NSURI corresponding to each namespace prefix. This can be done in multiple ways.

Here is a small complete XHTML file with all the decorations recommended by the W3C organization:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
 <title>My page title</title>
</head>
<body>
  <h1>Hello world</h1>
</body>
</html>

The xmlns attribute of the html element specifies that all its descendant elements are in the XHTML 1.0 Strict namespace.

The xml:lang="en" attribute specifies that the document is in English.

Here is a more elaborate example. This is the root element of an XSLT stylesheet. Prefix “xsl:” is used for the XSLT elements; prefix “fo:” is used for the XSL-FO elements; and a third namespace with prefix “date:” is also included. This document does not use a blank namespace.

<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:date="http://exslt.org/dates-and-times">