XML DOM » Objects » XTLRuntime

The XTLRuntime object is essentially a Node object which implements the following additional methods which can be called from within an XSL stylesheet:

  • absoluteChildNumber
  • ancestorChildNumber
  • childNumber
  • depth
  • formatDate
  • formatIndex
  • formatNumber
  • formatTime
  • uniqueID

Examples

Code:
<beers>
   <beer>
      <brewer>Badger</brewer>
      <name>Tanglefoot</name>
   </beer>
   <beer>
      <brewer>Wadworths</brewer>
      <name>6X</name>
   </beer>
   <beer>
      <brewer>Hop Back Brewery</brewer>
      <name>Summer Lightning</name>
   </beer>
</beers>

XSL:

<xsl:template match="/">
   <xsl:for-each select="beers/beer">
      <xsl:eval>childNumber(this)</xsl:eval>
      <xsl:value-of select="brewer"/>
      <br />
   </xsl:for-each>
</xsl:template>

JavaScript:

<script>
   xmldoc = new ActiveXObject("Microsoft.XMLDOM");
   xmldoc.async = false;
   xmldoc.load("beers.xml");

   xsldoc = new ActiveXObject("Microsoft.XMLDOM");
   xsldoc.async = false;
   xsldoc.load("beers.xsl");
</script>


<script>
   document.write(xmldoc.transformNode(xsldoc));
</script>
Output:
1 Badger
2 Wadworths
3 Hop Back Brewery
Explanation:

To demonstrate how you might use some of these stylesheet-specific methods, this example uses the the following 'beers' XML document and an XSL stylesheet that calls the childNumber method. The code loads both of these documents and then calls the transformNode method to apply the stylesheet to the XML document. The contents are printed with a document.write statement.

It is the stylesheet that ultimately determines how the XML is displayed, and applying the above stylesheet, only the 'brewer' elements will be printed, with each one being numbered as a result of calling the childNumber method.

Language(s): XSLT JavaScript XML

Properties

attributes

Syntax: node.attributes

This is a read-only property that returns a NamedNodeMap for nodes that can have attributes.

baseName

Syntax: document.basename

This is a read-only property that returns the base name for a node.

childNodes

Syntax: node.childNodes

This is a read-only property containing a node list of all children for those elements that can have them.

dataType

Syntax: node.dataType

This is a read-only property that specifies the data type for the node.

definition

Syntax: node.definition

This property returns the definition of the node in the DTD or schema.

firstChild

Syntax: node.firstChild

This is a read-only property that returns the first child node of a node. If there is none, it returns null.

lastChild

Syntax: node.lastChild

This is a read-only property that returns the last child node of a node. If there is none, it returns null.

namespaceURI

Syntax: object.namespaceURI

This property is read-only and returns the URI (Universal Resource Indentifier) of the namespace.

nextSibling

Syntax: node.nextSibling

This property returns the next node in the parent's child list, or null if there is none or the node is of a type that cannot be a child node (Attr, Document, DocumentFragment).

nodeName

Syntax: node.nodeName

This property is read-only and contains the name of the node, depending on type.

nodeType

Syntax: node.nodeType

This property is read-only and contains the name of the node, depending on type.

nodeTypedValue

Syntax: node.nodeTypedValue

This property contains the value of this node expressed in its defined data type.

nodeTypeString

Syntax: node.nodeTypeString

This property is read-only and returns the node type in string form.

nodeValue

Syntax: node.nodeValue

This property contains the value of the node, depending on type.

ownerDocument

Syntax: node.ownerDocument

This property returns the Document object to which the node belongs. If the node itself is a document, then it returns null.

parentNode

Syntax: node.parentNode

This is a read-only property that returns the parent node of all nodes except Document, DocumentFragment and Attr, which cannot have parent nodes.

parsed

Syntax: node.parsed

This property returns a boolean value of true if this node and all of its descendants have been parsed and instantiated. Otherwise it returns false.

prefix

Syntax: object.prefix

Property This property is read-only and returns the namespace prefix, or an empty string if none is specified. For example, it would return 'xxx' for the element xxx:yyy.

previousSibling

Syntax: node.previousSibling

This property returns the previous node in the parent's child list, or null if there is none or the node is of a type that cannot be an child node (Attr, Document, DocumentFragment).

specified

Syntax: node.specified

This property returns a boolean value which indicates whether or not this attribute has a value specified in the XML document.

text

Syntax: node.text

This property contains the text content of this node and its subtrees.

xml

Syntax: node.xml

This property contains the XML representation of this node and its descendants.

Methods

absoluteChildNumber

Syntax: xtlRuntime.absoluteChildNumber(pNode)

This method returns the index for this node in its parent's list of child nodes. (Indexing starts at 1.) Its one parameter is the node for which the number is to be returned.

ancestorChildNumber

Syntax: xtlRuntime.ancestorChildNumber(bstrNodeName, pNode)

This method returns the number of the nearest ancestor of a node with the specified node name.

appendChild

Syntax: node.appendChild(tagName)

This method appends a new child node to the list of children for this node.

childNumber

Syntax: object.childNumber(pNode)

This method returns the index for this node in its parent's list of child nodes. (Indexing starts at 1.) Its one parameter is the node for which the number is to be returned.

cloneNode

Syntax: node.cloneNode(deep)

This method creates a clone node which is an exact replica of this node.

depth

Syntax: xtlRuntime.depth(pNode)

This method returns a long integer indicating the depth within the document tree at which the specified node appears. The root node, or document element, is numbered 0, its children 1, and so on.

formatDate

Syntax: xtlRuntime.formatDate(varDate, bstrFormat, varDestLocale)

This method formats the supplied date using the specified formatting options.

formatIndex

Syntax: xtlRuntime.formatIndex(lIndex, bstrFormat)

This method formats the supplied integer using the specified numerical system.

formatNumber

Syntax: xtlRuntime.formatNumber(dblNumber, bstrFormat)

This method formats the supplied number using the specified format.

formatTime

Syntax: xtlRuntime.formatTime(varTime, bstrFormat, varDestLocale)

This method formats the supplied time using the specified formatting options.

hasChildNodes

Syntax: node.hasChildNodes

This method is a convenient way to determine whether a node has child nodes, returning true if it has, and false if not.

insertBefore

Syntax: node.insertBefore(newChild, refChild)

This method is used to insert a new child node before an existing one. If no child node exists, the new child node becomes the first.

removeChild

Syntax: node.removeChild(oldChild)

This method removes the specified node from the list of children and returns it.

replaceChild

Syntax: node.replaceChild(newChild, oldChild)

This method is used to replace one of a node's children with another. It returns the old child.

selectNodes

Syntax: node.selectNodes(patternString)

This method creates a NodeList of all matching descendant nodes returned by the specified pattern-matching operation.

selectSingleNode

Syntax: node.selectSingleNode(patternString)

This method returns an object for the first descendant node to match the specified pattern.

transformNode

Syntax: node.transformNode(stylesheet)

This method processes this node and its descendants using the specified XSL stylesheet, and returns the resulting transformation.

transformNodeToObject

Syntax: node.transformNodeToObject(stylesheet, outputObject)

This method processes this node and its descendants using the specified XSL stylesheet, and returns the resulting transformation in the specified object.

uniqueID

Syntax: xtlRuntime.uniqueID(pNode)

This method returns the unique identifier for the specified node.

See Also: