WebReference.com - Excerpt from Inside XSLT, Chapter 2, Part 4 (2/4) | WebReference

WebReference.com - Excerpt from Inside XSLT, Chapter 2, Part 4 (2/4)

To page 1current pageTo page 3To page 4
[previous] [next]

Inside XSLT

Figure 2.1, Planets.html in the Internet Explorer
Figure 2.1 Planets.html in the Internet Explorer.

To create the HTML table you see in Figure 2.1, then, I'll first match the <PLANETS> element, and then replace it with the HTML needed to create the HTML table itself. The <PLANETS> element is a child element of the root node, and because you can refer to the root node as "/", you can refer to the <PLANETS> element directly as "/PLANETS", without having to first use a template for the root node. This is an example of an XPath expression, and you'll see many more of them in Chapter 4.

Here's how I start the HTML table by matching the <PLANETS> element directly as "/PLANETS"-note that I use <xsl:apply-templates> to apply templates to any child nodes of <PLANETS>:

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/PLANETS">
    <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>
        .
        .
        .

Each <PLANET> child node has a <NAME>, <MASS>, <RADIUS>, and <DAY> child node, and I want to process them in that order so that they are added to the HTML table to match the table's headings. To specify the order in which they should be processed, I'll put the <xsl:value-of> elements in that order:


To page 1current pageTo page 3To page 4
[previous] [next]

Created: October 4, 2001
Revised: October 4, 2001


URL: http://webreference.com/authoring/languages/xml/insidexslt/chap2/4/2.html