WebReference.com - Part 1 of chapter 12 of XSLT Developer's Guide, from Osborne/McGraw-Hill (4/6) | WebReference

WebReference.com - Part 1 of chapter 12 of XSLT Developer's Guide, from Osborne/McGraw-Hill (4/6)

To page 1To page 2To page 3current pageTo page 5To page 6
[previous] [next]

XSLT Developer's Guide

Our task is to build a presentation-independent application, so we will work with the same data that is to be presented to either of the two clients: a web browser and a WAP microbrowser. We will accomplish this by writing two separate XSLT stylesheets.

Let us start with the first stylesheet, Present2HTML.xsl:

<?xml version="1.0"?>
<xsl:stylesheet
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns="http://www.w3.org/TR/REC-html40"
  version="1.0">

<xsl:output method="html"/> <xsl:template match="/"> <html> <head> <title>Customer Info</title> </head> <body> <h1>Results of customer query</h1> <h2><A NAME="toc">Key customers of Big Company Inc.:</A></h2> <xsl:for-each select="Customers/Company"> <p><a href="#{generate-id(.)}"> <b><xsl:value-of select="./Name"/></b> </a> </p> </xsl:for-each> <br/><br/> <h2>Customer Details</h2> <xsl:for-each select="//Company"> <h3><a name="{generate-id(.)}"><xsl:value-of select="Customer/Company"/></a></h3> <b>Company name: </b><xsl:value-of select="./Name"/><br/> <b>Company ID: </b><xsl:value-of select="@CompanyID"/>)<br/> <b>Customer contact: </b><xsl:value-of select="Contact"/><br/> <b>Phone: </b><xsl:value-of select="Phone"/><br/> <b>Sales representative: </b><xsl:value-of select="SalesRep"/><br/> <b>Address: </b><xsl:value-of select="Address/Address_line1"/> <xsl:value-of select="Address/Address_line2"/>, <xsl:value-of select="Address/City"/>, <xsl:value-of select="Address/State"/>, <xsl:value-of select="Address/ZIP"/> <br/> <p><u>About the company:</u> <xsl:value-of select="./About"/></p> <a href="#toc"><small>Back to customer list</small></a> <br/><br/><br/> </xsl:for-each> </body> </html> </xsl:template> </xsl:stylesheet>

Figure 12-1 shows the output resulting from the application of Present 2HTML.xsl to customers.xml. Note the use of generated IDs in the code to generate the links seen in the figure. If you click one of the links, say Ultra Machines Corporation, you will be taken to the screen shown in Figure 12-2.

HTML output from the application of Present2HTML.xsl to customers.xml rendered using IE6.0. We have used generated IDs to create links necessary for navigation from the list of companies to details about the companies. See also Figure 12-2.
Figure 12-1: HTML output from the application of Present2HTML.xsl to customers.xml rendered using IE6.0. We have used generated IDs to create links necessary for navigation from the list of companies to details about the companies. See also Figure 12-2.

HTML output from the application of Present2HTML.xsl to customers.xml rendered using IE6.0. When you click on the link for Ultra Machines Corporation shown in Figure 12-1, the details about that company are displayed as depicted in this figure.
Figure 12-2: HTML output from the application of Present2HTML.xsl to customers.xml rendered using IE6.0. When you click on the link for Ultra Machines Corporation shown in Figure 12-1, the details about that company are displayed as depicted in this figure.


To page 1To page 2To page 3current pageTo page 5To page 6
[previous] [next]

Created: May 28, 2002
Revised: May 28, 2002


URL: http://webreference.com/authoring/languages/xml/xsltdev/chap12/1/4.html