WebReference.com - Part 1 of chapter 12 of XSLT Developer's Guide, from Osborne/McGraw-Hill (5/6)
[previous] [next] |
XSLT Developer's Guide
Here all the details regarding a particular customer are provided. All these details can be displayed
in a web browser window since plenty of space is available to show them. However, how would you condense
the information if the size of the display were very limited, as in the case of a WAP device? To solve
this problem, we will show the use of a separate stylesheet called Present2WML.xsl. We will
display the same information as before, although we will organize it differently to accommodate the
much smaller form factor of WAP-enabled devices. In WML, the concept of cards is used for such
organization, and we can code for navigation from one card to another. Even if you have not programmed
in WML before, the following XSLT code should be fairly straightforward to follow:
<?xml version="1.0"?>
<!-- Stylesheet Present2WML.xsl -->
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output
method="xml"
doctype-public="-//WAPFORUM//DTD WML 1.1//EN"
doctype-system="http://www.wapforum.org/DTD/wml_1.1.xml"/>
<xsl:template match="/">
<wml>
<!-- Card showing the customer list -->
<card id="toc" title="Customer List">
<p><b>Results</b></p>
<xsl:for-each select="Customers/Company">
<p>
<b><anchor>
<xsl:value-of select="./Name"/>
<go href="#{generate-id(.)}"/>
</anchor></b>
</p>
</xsl:for-each>
</card>
<xsl:for-each select="Customers/Company">
<card id="{generate-id(.)}" title="Customer info">
<p>
<b><xsl:value-of select="./Name"/></b>
</p>
<p>
<small>
<b>ID: </b> <xsl:value-of select="@CompanyID"/><br/>
<b>Contact: </b><xsl:value-of select="Contact"/><br/>
<b>Phone: </b><xsl:value-of select="Phone"/><br/>
<!--
Give the user the option to go back to the list,
or view more details about the customer.
-->
<anchor>Back to list<go href="#toc"/></anchor><br/>
... or Down for more ...<br/>
<b>Sales Rep: </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/>
<!--
Give the user the option to go back to the list,
or view more details about the customer.
-->
<anchor>Back to list<go href="#toc"/></anchor><br/>
... or Down for more ...<br/>
<b>About:</b>
<!--
All info about the customer has been shown.
Show the user a link to go back to the list.
-->
<xsl:value-of select="./About"/><br/>
<anchor>Back to list<go href="#toc"/></anchor><br/>
</small>
</p>
</card>
</xsl:for-each>
</wml>
</xsl:template>
</xsl:stylesheet>
An excerpt from the output resulting from the application of Present2WML.xsl to the
source tree from customers.xml is shown here. For the sake of brevity, we have shown
the detailed card only for the first customer, Powergadgets, Inc.:
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE wml
PUBLIC "-//WAPFORUM//DTD WML 1.1//EN"
"http://www.wapforum.org/DTD/wml_1.1.xml">
<wml>
<card id="toc" title="Customer List">
<p><b>Results</b></p>
<p><b><anchor>Powergadgets, Inc.<go href="#d1e4"/></anchor></b></p>
<p><b><anchor>Ultimate Tools, Inc.<go href="#d1e51"/></anchor></b></p>
<p><b><anchor>Ultra Machines Corporation<go href="#d1e99"/></anchor></b></p>
</card>
<card id="d1e4" title="Customer info">
<p><b>Powergadgets, Inc.</b></p>
<p><small><b>ID: </b>7001<br/><b>Contact: </b>
John Doe<br/>
<b>Phone: </b>972-777-1111<br/>
<anchor>Back to list<go href="#toc"/></anchor><br/>
... or Down for more ...<br/>
<b>Sales Rep: </b>Mark McCarthy<br/>
<b>Address: </b>111 Corporate Boulevard,
Addison, TX, 75001<br/>
<anchor>Back to list<go href="#toc"/></anchor><br/>
... or Down for more ...<br/>
<b>About:</b> Powergadgets is a Fortune 222 company and has
been doing business with us for 20 years. Roughly 40 % of
our revenue come from Powergadgets. This customer should be
treated very well. Should any problem arise at all with
this customer, make sure that you bring the matter to the
attention of the VP of Sales, Jerry Salinger.<br/>
<anchor>Back to list<go href="#toc"/></anchor><br/>
[previous] [next] |
Created: May 28, 2002
Revised: May 28, 2002
URL: http://webreference.com/authoring/languages/xml/xsltdev/chap12/1/5.html

Find a programming school near you