The XSLT examples indicate that there can be conflicts once elements from different documents are mixed: an XSLT program contains elements that should simply be output; things will get tricky once an XSLT program has to create an XSLT program.
Namespaces were introduced to make elements and attributes unique by linking them to URIs.
The reserved attribute xmlns connects a prefix to a URI — without a prefix a URI is defined as default namespace which is used whenever there is no prefix:
<ats:scope xmlns:ats="http://www.inf.uos.de/axel" xmlns="http://www.w3.org/"> <!-- here the prefix ats is visible --> <html/> <!-- has default namespace --> </ats:scope>
The prefix is visible in the element in which it is defined and in all nested element. The default namespace is used similarly.
The default namespace is empty if xmlns="" is specified. Elements without a prefix then belong to no namespace.
The default namespace does not apply to attributes — by default attributes are in no namespace.
A name consists of a prefix and a local name, separated by exactly one colon. Names are equal if their local parts (following the colon if any) are equal and if, if present, the prefixes link to URIs with the same sequence of characters (the prefixes may be different).
<eg xmlns:n1="http://www.w3.org/" xmlns:n2="http://www.w3.org/"> <ok a="A" b="B"/> <no n1:a="A" n2:a="B"/><!-- duplicate attribute --> <ok n1:a="A" a="B"/> </eg>
DTDs are not aware of namespaces. To validate this example all four attributes have to be declared :
<!ELEMENT zb ( ok | no )+>
<!ATTLIST zb
xmlns:n1 CDATA #FIXED "http://www.w3.org/"
xmlns:n2 CDATA #FIXED "http://www.w3.org/"
>
<!ENTITY % atts "
a CDATA #IMPLIED
b CDATA #IMPLIED
n1:a CDATA #IMPLIED
n2:a CDATA #IMPLIED
">
<!ELEMENT ok EMPTY>
<!ATTLIST ok %atts;>
<!ELEMENT no EMPTY>
<!ATTLIST no %atts;>
The example turns out to be valid — but it is incorrect if namespaces are considered. Things get really tricky if a namespace is introduced in an external, defaulted attribute.