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

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

Additional Properties

Name
Type
Description
async
Boolean
True
if the document is to be loaded asynchronously.
parseError
IXMLDOMParseError
The last parser error.
readyState
Long
Current state of readiness for use. Used when loading asynchronously. The values are Uninitialized (0), Loading (1), Loaded (2), Interactive (3), and Completed (4).
validateOnParse
Boolean
Requests validation of the document against its DTD or schema.

IXMLDOMNode

This object represents a node in the document tree. Note that the tree conforms to the DOM model, which is not always the same as the XPath model described in Chapter 2; for example, the way namespaces are modeled is different, and text nodes are not necessarily normalized.

There are subclasses of
IXMLDOMNode
for all the different kinds of node found in the tree. I have not included descriptions of all these, since they are not directly relevant to XSLT and XPath processing. The only subclass I have included is
IXMLDOMDocument
, which can be regarded as representing either the whole document or its root node, depending on your point of view.

Methods

The methods available on
IXMLDOMNode
that are relevant to XSLT and XPath processing are listed below. Most often, these methods will be applied to the root node (the DOM
Document
object), but they can be applied to any node.

Name
Returns
Description
selectNodes
IXMLDOMNodeList
Executes an XPath expression and returns a list of matching nodes.
selectSingleNode
IXMLDOMNode
Executes an XPath expression and returns the first matching node.
transformNode
String
Applies a stylesheet to the subtree rooted at this node, returning the result as a string. The argument identifies the XSLT stylesheet. This will usually be a
Document
, but it may be a
Node
representing an embedded stylesheet within a
Document
. The serialized result of the transformation is returned as a string of characters (the

encoding is ignored).
transformNodeToObject
(Nothing)
Applies a stylesheet to the subtree, placing the result into a supplied document or stream. The difference between this and
transformNode()
is that the destination of the transformation is supplied as a second argument. This will usually be a
Document
. It may also be a
Stream
.

Properties

The most useful properties are listed below. Properties whose main purpose is to navigate through the document are not listed here, because navigation can be achieved more easily using XPath expressions.

Name
Type
Description
baseName
String
The local name of the node, excluding any namespace prefix.
namespaceURI
String
The namespace URI.
nodeName
String
The name of the node, including its namespace prefix if any. Note that unlike the XPath model, unnamed nodes are given conventional names such as
“#document”
,
“#text”
, and
“#comment”
.
nodeTypeString
String
Returns the type of node in string form. For example,
“element”
,
“attribute”
, or
“comment”
.
nodeValue
Variant
The value stored in the node. This is not the same as the XPath string value; for elements, it is always null.
prefix
String
The prefix for the namespace applying to the node.
text
String
Text contained by this node (like the XPath string value).
xml
String
XML representation of the node and its descendants.

IXMLDOMNodeList

This object represents a list of nodes. For our present purposes, we are interested in this object because it is the result of the
selectNodes()
method.

An
IXMLDOMNodeList
is returned as a result of the
selectNodes()
method: it contains the list of nodes selected by the supplied XPath expression. You can process all the nodes in the list either by using the
nextNode()
method or by direct indexing using the
item
property.

Methods

Name
Returns
Description
item
IXMLDOMNode
item(N)
gets the node at position N.
nextNode
IXMLDOMNode
Gets the next node.
reset
(Nothing)
Resets the current position.

Properties

Name
Type
Description
length
Long
Identifies the number of nodes in the collection.

IXMLDOMParseError

This object is accessible through the
parseError
property of the
IXMLDOMDocument
interface.

Properties

Name
Type
Description
errorCode
Long
The error code.
filepos
Long
The character position of the error within the XML document.
line
Long
The line number of the error.
linepos
Long
The character position in the line containing the error.
reason
String
Explanation of the error.
srcText
String
The XML text in error.
url
String
The URL of the offending document.

IXMLDOMSelection

This object represents a selection of nodes. It is returned as the result of the
selectNodes()
method when the target document implements the
IXMLDOMDocument2
interface.

It's simplest to think of this object as a stored expression that returns a list of nodes on demand. It's rather like a relational view: You don't need to know whether the results are actually stored, or whether they are obtained as required.

This interface extends the
IXMLDOMNodeList
interface.

Methods

Name
Returns
Description
clone
IXMLDOMSelection
Produces a copy of this
IXMLDOMSelection
.
getProperty
String
Returns the value of a named property such as
SelectionLanguage
.
item
IXMLDOMNode
item(N)
gets the node at position N.
matches
IXMLDOMNode
Tests whether the given node is a member of the set of nodes (returns null if no match; otherwise, the node from which the selection succeeds).
nextNode
IXMLDOMNode
Gets the next node.
reset
(Nothing)
Resets the current position.

Properties

Name
Type
Description
context
IXMLDOMNode
Establishes the context node for evaluating the expression. Changing the context node implicitly resets the current list of nodes, replacing it with a new list.
expr
String
The XPath expression that determines the nodes selected. This can be changed at any time; doing so implicitly resets the current list of nodes, replacing it with a new list.
length
Long
Identifies the number of nodes in the collection.

IXSLProcessor

An
IXSLProcessor
object represents a single execution of a stylesheet to transform a source document.

The object is normally created by calling the
createProcessor()
method of an
IXSLTemplate
object.

The transformation is achieved by calling the
transform()
method.

Methods

Name
Returns
Description
addParameter
(Nothing)
Sets the value of a stylesheet parameter. The first argument is the local name of the parameter, the second is the parameter value, and the third is the namespace URI (usually “”). The value can be a boolean, a number, or a string, or a
Node
or
NodeList
.
reset
(Nothing)
Resets the state of the processor and aborts the current transform.
setStartMode
(Nothing)
Sets the initial mode. There are two arguments, representing the local name and the namespace URI parts of the mode name.
transform
Boolean
Applies the stylesheet (from which this
XSLProcessor
was derived) to the source document identified in the input property. The result tree is accessible through the output property.
If the source document is being loaded asynchronously, a return value of
False
means that the transformation needs to wait until more input is available. It can be resumed by calling
transform()
again later. The current state of the transformation can be determined from the
readyState
property.

Properties

Name
Type
Description
input
Variant
XML source document to transform. This is normally supplied as a DOM
Document
, but it may also be a
Node
. The input can also be supplied as an
IStream
.
output
Variant
Output of the transformation. If you don't supply an output object, the processor will create a
String
to hold the output, which you can read using this property. If you prefer, you can supply an object such as a DOM
Document
, a DOM
Node
, or an
IStream
to receive the output.
ownerTemplate
IXSLTemplate
The
XSLTemplate
object used to create this processor object.
readyState
Long
The current state of the transformation. This will be
READYSTATE_COMPLETE
(3) when the transformation is finished.
startMode
String
Name of the initial mode. See
setStartMode()
method above.
startModeURI
String
Namespace of the initial mode. See
setStartMode()
method above.
stylesheet
IXMLDOMNode
The current stylesheet being used.

IXSLTemplate

An
IXSLTemplate
object represents a compiled stylesheet in memory. If you want to use the same stylesheet more than once, then creating an
IXSLTemplate
and using it repeatedly is more efficient than using the raw stylesheet repeatedly using
transformNode()
.

Methods

Name
Returns
Description
createProcessor
IXSLProcessor
Creates an
IXSLProcessor
object.
This method should only be called after the stylesheet property has been set to associate the
IXSLTemplate
object with a stylesheet.
It creates an
IXSLProcessor
object, which can then be used to initiate a transformation of a given source document.

Properties

Name
Type
Description
stylesheet
IXMLDOMNode
Identifies the stylesheet from which this
IXSLTemplate
is derived.

Setting this property causes the specified stylesheet to be compiled; this
IXSLTemplate
object is the reusable representation of the compiled stylesheet.

The DOM
Node
representing the stylesheet will normally be a DOM
Document
object, but it may be an Element representing an embedded stylesheet.

Other books

Hamsikker 2 by Russ Watts
Life Eternal by Woon, Yvonne
Our Vinnie by Julie Shaw
The Revenge of the Radioactive Lady by Elizabeth Stuckey-French
The Way of Wyrd by Brian Bates
The Shadow Club by Neal Shusterman
The Wayfarer King by May, K.C.
03 - Sworn by Kate Sparkes