Using XSLT and JavaScript in the Internet Explorer

Using XSLT and JavaScript in the Internet Explorer

The XSLT processor in the Internet Explorer 5.5 is part of the MSXML3 XML parser, and if you access MSXML3 directly, using JavaScript, you dont have to modify the original planets.xml and planets.xsl ( Listings 1.1 and 1.2) as you saw in the previous section. Youll see how this works in Chapter 10, but heres a Web page, xslt.html, that uses JavaScript and MSXML3 to transform planets.xml using planets.xsl and displays the results (note that you can adapt this document to use your own XML and XSLT documents without writing any JavaScript; just replace the names planets.xml and planets.xsl with the names of your XML and XSL documents):

Listing 1.5 Microsoft Internet Explorer JavaScript Transformation
 <HTML>      <HEAD>          <TITLE>XSLT Using JavaScript</TITLE>          <SCRIPT LANGUAGE="JavaScript">          <!--         function xslt()          {             var XMLDocument = new ActiveXObject('MSXML2.DOMDocument.3.0');              var XSLDocument = new ActiveXObject('MSXML2.DOMDocument.3.0');              var HTMLtarget = document.all['targetDIV'];              XMLDocument.validateOnParse = true;              XMLDocument.load('planets.xml');              if (XMLDocument.parseError.errorCode != 0) {                  HTMLtarget.innerHTML = "Error!"                   return false;              }              XSLDocument.validateOnParse = true;              XSLDocument.load('planets.xsl');              if (XSLDocument.parseError.errorCode != 0) {                  HTMLtarget.innerHTML = "Error!"                   return false;              }              HTMLtarget.innerHTML = XMLDocument.transformNode(XSLDocument);              return true;          }          //-->          </SCRIPT>      </HEAD>      <BODY onload="xslt()">          <DIV ID="targetDIV">          </DIV>      </BODY>  </HTML> 

This Web page produces the same result you see in Figure 1.3, and it does so by loading planets.xml and planets.xsl directly and applying the MSXML3 parser to them. These files, planets.xml and planets.xsl, are the same as weve seen throughout this chapter, without the modifications necessary in the previous topic, where we navigated to planets.xml directly using the Internet Explorer. See Chapter 10 for more information.

Using VBScript

You can also use the Internet Explorers other scripting language, VBScript, to achieve the same results if youre more comfortable with VBScript.

Inside XSLT
Inside Xslt
ISBN: B0031W8M4K
Year: 2005
Pages: 196

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: