XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition (19 page)

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
9.02Mb size Format: txt, pdf, ePub
ads

There are several possible ways of classifying these nodes. We could distinguish those that can have children (element and document nodes), those that can have a parent (everything except the document node), those that have a name (elements, attributes, namespaces, and processing instructions) or those that have their own textual content (attributes, text, comments, processing instructions, and namespace nodes). Because each of these criteria gives a different possible class hierarchy, the XDM model instead leaves the hierarchy completely flat, and defines all these characteristics for all nodes. Where a characteristic isn't applicable to a particular kind of node, XDM generally defines its value as an empty sequence, though sometimes when you access the property from a real XPath expression what you actually get back is a zero-length string.

So if we show the class hierarchy in UML notation, we get the simple diagram shown in
Figure 2-6
.

UML (the Unified Modeling Language) provides a set of diagrammatic conventions for object-oriented analysis and design. For information about UML, see
http://www.uml.org/
.

This diagram looks superficially similar to the tree we saw earlier, but this time I'm not showing a specific tree, I'm showing a class hierarchy: the boxes represent classes or types, and the arrow represents an
is-a-kind-of
relationship; for example a comment
is-a-kind-of
node. The earlier diagram was just one example of a particular tree, whereas now we are considering the structure of all possible trees.

I've already hinted at some of the properties and relationships of these nodes. Let's look at the properties and relationships in more detail, and then add them to the diagram.

The Name of a Node

In general, a node has a name. Nodes can (and often do) have simple names, but in the general case, node names are qualified by the namespace they are in.

An element or attribute name as written in a textual XML document is a
lexical QName
. (QName stands for Qualified Name.) A lexical QName has two parts: the prefix, which is the part of the QName before the
:
as written in the source XML, and the local part, which is the part of the QName after the
:
. If there is no colon, the prefix is the zero-length string. For example,
xsl:stylesheet
is a lexical QName, with prefix
xsl
and local-name
stylesheet
.

In XDM, however, a name is represented by an
expanded QName
. This is an atomic value whose type is
xs:QName
. The expanded QName has three parts, though there is no explicit syntax for displaying it. The three parts are the prefix, the namespace URI, and the local part.

The namespace URI is derived from the prefix used in the source document, by finding the namespace declarations that are in scope where it is used, while the local name is again the part of the lexical QName after the
:
. The prefix is retained as part of the expanded name, to allow a document to be serialized using the author's original choice of prefixes, but it is not considered to be a significant part of the name. So the expanded QName corresponding to the lexical QName
xsl:stylesheet
has namespace URI
http://www.w3.org/1999/XSL/Transform
(assuming the standard namespace declarations are used), and local part
stylesheet
, while also retaining the prefix
xsl
for display purposes.

BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition
9.02Mb size Format: txt, pdf, ePub
ads

Other books

Goddess for Hire by Sonia Singh
Nod by Adrian Barnes
The Firebug of Balrog County by David Oppegaard
Pieces of Lies by Angela Richardson
Play On by Heather C. Myers