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

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

The name of an element or attribute node is accessible, as an
xs:QName
value, using the
node-name()
function defined in Chapter 13. The namespace URI and local-name parts of the name are also separately accessible (as strings) using the functions
namespace-uri()
and
local-name()
. If you want the original lexical QName, it can be obtained using the
name()
function.

Document nodes, comments, and text nodes have no name, and for these, the
node-name()
function returns the empty sequence, which is the XDM equivalent of a null value. (Note that this differs from the DOM, where names such as
#comment
are used.)

The name of a processing instruction is the
PITarget
from the source XML: this contains a local name but no namespace URI, as processing instruction names are not subject to namespace rules.

The name of a namespace node is, by convention, the namespace prefix from the original namespace declaration (without the
xmlns:
part). For example, the namespace declaration
xmlns:acme=“http://acme.com/xml”
generates a namespace node with name
acme
, while the default namespace declaration
xmlns=“http://acme.com/xml”
generates a namespace node whose name is effectively null (represented as an empty sequence). The name of a namespace node, like the name of any other node, is an
xs:QName
, but the namespace URI part of this
xs:QName
is always null, while the local-name part holds the namespace prefix.

The String Value of a Node

Every node has a string value, which is a sequence of Unicode characters. The string value depends on the kind of node, as shown in the table below:

Node Kind
String Value
Text
The text as it appears in the source XML document, except that the XML parser will have replaced every end-of-line sequence (for example, CRLF as used on Windows platforms) by a single newline (
x0A
) character.
Comment
The text of the comment, minus the delimiters.
Processing instruction
The
data
part of the source processing instruction, not including the whitespace that separates it from the
PITarget
. For example, given the processing instruction
this?>
, the string value is
this
.
Attribute
The string value is the value of the attribute as written, modified by any whitespace normalization done by the XML parser and schema processor. The detailed rules for whitespace normalization of attributes depend on the attribute type.
Document or element
The concatenation of the string values of all the element and text children of this node. Or, to look at it another way: the concatenation of all the
PCDATA
contained in the element (or for the document node, the entire document) after stripping out all markup. (This again differs from the DOM, where the
nodeValue
property in these cases is null.)
Namespace
By convention, the URI of the namespace being declared.

Other books

Sodom and Detroit by Ann Mayburn
The Immortal Rules by Julie Kagawa
The Black Swan by Philippa Carr
Contango (Ill Wind) by James Hilton
My Life as a Cartoonist by Janet Tashjian
Or Not to Be by Lanni, Laura
Star Born by Andre Norton
The Wise Woman by Philippa Gregory