Main Page

XSLT support in IE

As you can see, XSLT is actually another language based on XML. The document element is
, which also specifies the version of XSLT being used (1.0) and the namespace URL.
Without this information, an XSLT processor can’t properly use the style sheet.
The next line contains the
element, which specifies the rules by which the output
should be handled. For the
attribute, three possible values exist: html, xml, and text. When you
, the parser treats the output as HTML, meaning that the strict XML rules are not applied;
forces all XML rules to be applied to the output, whereas
only outputs the content con-
tained outside of elements.
Next come the templates. The first template matches the document element, as indicated by
XPath expression always refers to the document element. There is HTML code inside the template,
right up until the
element, which tells the parser to apply any matching
templates to the child nodes (which is an XPath expression for any child node). Because a template is
defined that matches that pattern, processing continues.
Inside the second template, notice the
element. Immediately following is the
element, which is used to output a value from the source XML. The
attribute is another XPath
, which tells the transformer to output the text value of the
element (which
is the text contained inside of it). After that, there’s a comma, then the opening
tag, followed by
element. This time, the
attribute points to the
attribute of
and so the transformer outputs that value.
When this XSLT style sheet is run against the XML file, the result is the HTML shown previously.
Although this is a simple example, it does show some of the unique capabilities of XSLT.
If you’d like to learn more about XSLT, consider picking up XSLT 2.0: Programmer’s Reference, 3rd
Edition (Wiley Publishing, Inc., ISBN 0-7645-6909-0).
XSLT support in IE
Beginning with MSXML 3.0, Internet Explorer fully supports XSLT 1.0. If you are still using Internet
Explorer 5.0 or 5.5, you should install a new version of MSXML manually; if you are using IE 6.0, then
you already have at least MSXML 3.0.
The simplest way to conduct an XSLT transformation is to load the source XML and the XSLT file each
into their own DOMs and then use the proprietary
var sResult = oXmlDom.transformNode(oXslDom);
This example loads a DOM with XML and a DOM with the XSLT style sheet (note that you can load XSLT
into an XML DOM because it is just another form of XML). Then, the third line calls the
method on the document, passing in the DOM containing the XSLT code as its only argument. The vari-
is then filled with a string resulting from the transformation.
XML in JavaScript
18_579088 ch15.qxd 3/28/05 11:42 AM Page 473

JavaScript EditorFree JavaScript Editor     Ajax Editor