Working with a Source Tree
To locate the data in a transformation, the XSLT processor uses the XPath language to navigate the source tree of the document.
XPath treats an XML document as a tree of nodes. In general, a node corresponds to an element or an attribute in the XML document, except for the root node. The root node represents the source document as whole and contains, but does not correspond to, the top-level element in the XML document. A collection of nodes is called a node-set.
The following table shows seven types of nodes. A document does not necessarily contain all seven node types.
Node Type | Description |
---|---|
Root | The top-level node. The root node represents the document itself. |
Element | Corresponds to an XML element in the source document. For example, a <book>The Encyclopedia of Cows</book> or <book title="The Encyclopedia of Cows"/> element is represented by a book node. |
Attribute | Represents an attribute of an XML element. For example, the <book title="The Encyclopedia of Cows"/> element has a corresponding attribute node with title as the node name and "The Encyclopedia of Cows" as the node value. Notice that xmlns:ns="a_namespace_uri" corresponds to a namespace node, but not to an attribute node. |
Text | Represents a sequence of consecutive characters that forms non-markup character data of an XML element. For example, for the <book>The Encyclopedia of Cows</book> element in the XML document, there is a corresponding text node for the text of "The Encyclopedia of Cows" . However, for <book>The Encyclopedia of <animal>Cows</animal></book> , there will be two text nodes: one for the text of "The Encyclopedia of" and the other for "Cows" . |
Namespace | Corresponds to a distinct namespace prefix that is in scope for an element. A namespace is declared with an xmlns: attribute of an element. For example, for <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> , the namespace node refers to the "xmlns:xsl="http://www.w3.org/1999/XSLT/Transform" part of the element. Namespace nodes might or might not be present in a document. |
Processing-instruction | Represents a processing instruction declared in the source XML document, such as <?xml-stylesheet type="text/xsl" href="myXSLT.xsl"?> . However, <?xml version="1.0"?> does not correspond to a processing node. Notice that a processing-instruction node does not represent processing instructions within the document type declaration of the XML document. |
Comment | Represents a comment in the XML document. For example, <!-- this is a comment --> is represented by a comment node. Notice that a comment node does not represent comments within the document type declaration of the XML document. |
See Also
XPath Nodes Example | The XSLT Processor