Internet Explorer and XML Data Islands

Internet Explorer and XML Data Islands

The Internet Explorer supports a special tag, <XML> , that you can use to create XML islands. An XML island can enclose either straight XML or a reference to an XML document. For more on XML islands and how to create them, see Chapter 7 in Inside XML .

XML islands make it easy to load XML and XSL documents, so theyre worth taking a look at here. In the following example, I create two XML islands, sourceDocument and stylesheet , and load planets.xml and planets.xsl just by referring to them with the src attribute:

 <HTML>      <HEAD>          <TITLE>              The Planets Table          </TITLE>          <XML id="sourceDocument" src="planets.xml"></XML>          <XML id="stylesheet" src="planets.xsl"></XML>          .          .          . 

Now all I have to do to perform the XSLT transformation is use the transformNode method as before, and assign the results to a target <DIV> element to display those results:

Listing 10.4 Loading XML and XSL Documents Using XML Islands
 <HTML>      <HEAD>          <TITLE>              The Planets Table          </TITLE>          <XML id="sourceDocument" src="planets.xml"></XML>          <XML id="stylesheet" src="planets.xsl"></XML>          <SCRIPT FOR="window" EVENT="onload">              targetDIV.innerHTML = sourceDocument.transformNode(stylesheet.XMLDocument);          </SCRIPT>      </HEAD>      <BODY>          <CENTER>              <DIV id="targetDIV"></DIV>          </CENTER>      </BODY>  </HTML> 

That's all it takes. Note that by default, the Internet Explorer 5.5 and earlier uses the older XSLT processor, as discussed in Chapter 2 (unless you've specifically installed the MSXML3 processor in replace mode, or IE 6.0, also in Chapter 2). If you're using IE 5.5 or earlier, you have to use an old-style Internet Explorer stylesheet, relying on no default rules and using the old XSL namespace, as in this example:

Listing 10.5 Old-style Internet Explorer Stylesheet
 <?xml version="1.0"?>  <xsl:stylesheet version="1.1" xmlns::xsl="http://www.w3.org/TR/WD-xsl">      <xsl:template match="/">          <HTML>              <HEAD>                  <TITLE>                      The Planets Table                  </TITLE>              </HEAD>              <BODY>                  <H1>                      The Planets Table                  </H1>                  <TABLE BORDER="2">                      <TR>                          <TD>Name</TD>                          <TD>Mass</TD>                          <TD>Radius</TD>                          <TD>Day</TD>                      </TR>                      <xsl:apply-templates/>                  </TABLE>              </BODY>          </HTML>      </xsl:template>      <xsl:template match="PLANETS">          <xsl:apply-templates/>      </xsl:template>      <xsl:template match="PLANET">         <TR>            <TD><xsl:value-of select="NAME"/></TD>            <TD><xsl:value-of select="MASS"/></TD>            <TD><xsl:value-of select="RADIUS"/></TD>            <TD><xsl:value-of select="DAY"/></TD>         </TR>     </xsl:template>  </xsl:stylesheet> 

As you can see, theres plenty you can do with JavaScript and XSLT in the Internet Explorer. For more information, see the Microsoft XSLT Developers guide which is currently at http://msdn.microsoft.com/library/default.asp?URL=/library/psdk/xmlsdk/xslp8tlx.htm.

Its time to turn to interfacing XSLT to Java, starting by calling Java directly from XSLT processors.



Inside XSLT
Inside Xslt
ISBN: B0031W8M4K
EAN: N/A
Year: 2005
Pages: 196

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net