Element Nodes The XPath Data Model

page 42 • The XML 1.0 specification defines two attributes xml:lang and xml:space that work like default namespaces. In other words, if the auth:author element in our sample document contains the attribute xml:lang=en_us , that attribute applies to all elements contained inside auth:author . Even though that attribute might apply to the last-name element, last-name wont have an attribute node named xml:lang . Similarly, the xml:space defines whether whitespace in an element should be preserved; valid values for this attribute are preserve and default . Whether these attributes are in effect for a given element or not, the only attribute nodes an element node contains are those tagged in the document and those defined with a default value in the DTD. For more information on language codes and whitespace handling, see the discussions of the XPath lang function and the XSLT xsl:preserve-space and xsl:strip- space elements.

3.1.4 Text Nodes

Text nodes are refreshingly simple; they contain text from an element. If the original text in the XML document contained entity or character references, they are resolved before the XPath text node is created. The text node is text, pure and simple. A text node is required to contain as much text as possible; the next or previous node cant be a text node. You might have noticed that there are no CDATA nodes in this list. If your XML document contains text in a CDATA section, you can access the contents of the CDATA section as a text node. You have no way of knowing if a given text node was originally a CDATA section. Similarly, all entity references are resolved before anything in your stylesheet is evaluated, so you have no way of knowing if a given piece of text originally contained entity references.

3.1.5 Comment Nodes

A comment node is also very simple—it contains some text. Every comment in the source document except for comments in the DTD becomes a comment node. The text of the comment node returned by the text node test contains everything inside the comment, except the opening -- and the closing -- .

3.1.6 Processing Instruction Nodes

A processing instruction node has two parts, a name returned by the name function and a string value. The string value is everything after the name, including whitespace, but not including the ? that closes the processing instruction.

3.1.7 Namespace Nodes

Namespace nodes are almost never used in XSLT stylesheets; they exist primarily for the XSLT processors benefit. Remember that the declaration of a namespace such as xmlns:auth=http:www.authors.net , even though it is technically an attribute in the XML source, becomes a namespace node, not an attribute node.

3.2 Location Paths

One of the most common uses of XPath is to create location paths. A location path describes the location of something in an XML document. In our examples in the previous chapter, we used location paths on the match and select attributes of various XSLT elements. Those