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
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:
XML:
<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>
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:
Code (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>
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. The output will appear like this:
Output:
1 Badger
2 Wadworths
3 Hop Back Brewery
denotes a Microsoft extension to the W3C DOM.
PROPERTIES
attributes Property
This is a read-only property that returns an
NamedNodeMap for nodes that can have
attributes.
Syntax: Node.attributes
baseName Property
This is a read-only property that returns the base name for a node.
Syntax: Node.baseName
childNodes Property
This is a read-only property containing a node list of all children for those elements that
can have them.
Syntax: Node.childNodes
dataType Property
This is a read-only property that specifies the data type for the node.
Syntax: Node.dataType
definition Property
This property returns the definition of the node in the DTD or schema.
Syntax: Node.definition
firstChild Property
This is a read-only property that returns the first child node of a node. If there is none,
it returns null.
Syntax: Node.firstChild
lastChild Property
This is a read-only property that returns the last child node of a node. If there is none,
it returns null.
Syntax: Node.lastChild
namespaceURI Property
This property is read-only and returns the URI (Universal Resource Indentifier) of the
namespace.
Syntax: Node.namespaceURI