Main Page


You don’t need to start the transformation from the document level; every node has the
method. The following are all valid:
sResult = oXmlDom.documentElement.transformNode(oXslDom);
sResult = oXmlDom.documentElement.childNodes[1].transformNode(oXslDom);
sResult = oXmlDom.getElementsByTagName(“name”)[0].transformNode(oXslDom);
sResult = oXmlDom.documentElement.firstChild.lastChild.transformnode(oXslDom);
If you call
from anywhere other than the document element, you start the transfor-
mation at that spot. The XSLT style sheet, however, still has access to the full XML document from which
that node came.
The more complicated way to use XSLT in IE is to use an XSL template and processor. To do so, you
must use a few more ActiveX controls from the MSXML library. First, the XSLT file must be loaded into
a free-threaded DOM document, which behaves just like a regular DOM document but is thread-safe:
var oXslDom = new ActiveXObject(“MSXML2.FreeThreadedDOMDocument”);
oXslDom.async = false;
After the free-threaded DOM document is created and loaded, it must be assigned to an XSL template,
which is another ActiveX object:
var oTemplate = new ActiveXObject(“MSXML2.XSLTemplate”);
oTemplate.stylesheet = oXslDom;
The XSL template is then used to create an XSL processor (you guessed it, another ActiveX object):
var oProcessor = oTemplate.createProcessor();
With the processor created, you set the
property equal to the XML DOM node to transform and
then call the
oProcessor.input = oXmlDom;
The resulting string is then accessible from the output property:
var sResult = oProcessor.output;
All this code mimics the functionality of
. You may be wondering why anyone would
use the XSL template/processor methodology if it does the same thing as
. The answer
is that the processor allows you more control over XSLT.
For example, XSLT style sheets accept parameters that can be passed in and used as local variables.
Consider the following style sheet:
<?xml version=”1.0”?>
<xsl:stylesheet version=”1.0” xmlns:xsl=””>
<xsl:output method=”html” />
Chapter 15
18_579088 ch15.qxd 3/28/05 11:42 AM Page 474

JavaScript EditorFree JavaScript Editor     Ajax Editor