|
|
![]() |
|
This article is in four parts:The Style SheetsThis section presents the three style sheets. HTML Style SheetThe style sheet for HTML documents is in Listing 4.5. It builds a short table of contents before listing the various news items. Listing 4.5 html.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>Pineapplesoft Daily</TITLE></HEAD>
<BODY><H1>Pineapplesoft Daily</H1>
<H2><A NAME="toc">Today's News</A></H2>
<xsl:for-each select="News/Item">
<P><A HREF="#{generate-id(.)}">
<xsl:value-of select="Title"/></A><BR/>
<SMALL>by <xsl:value-of select="Author"/></SMALL><BR/>
<xsl:value-of select="Abstract"/></P>
</xsl:for-each>
<H2>News Items</H2>
<xsl:for-each select="News/Item">
<H3><A NAME="{generate-id(.)}"><xsl:value-of
select="Title"/></A></H3>
<P><I>by <xsl:value-of select="Author"/></I></P>
<xsl:for-each select="Para">
<P><xsl:value-of select="."/></P>
</xsl:for-each>
<A HREF="#toc"><SMALL>More News</SMALL></A><BR/>
</xsl:for-each>
</BODY></HTML>
</xsl:template>
Figure 4.7 presents the result in a browser. ![]() Figure 4.7 The HTML document in a browser.
WML Style SheetListing 4.6 is the style sheet to generate WML. Again, it starts with a table of contents. Unlike the HTML document, however, it places each news item on a different card. Listing 4.6 wml.xsl<?xml version="1.0"?>
<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 id="toc" title="Pineapplesoft Daily">
<p align="center"><b>Today's News</b></p>
<xsl:for-each select="News/Item">
<p><anchor><xsl:value-of select="Title"/><go
href="#{generate-id(.)}"/></anchor></p>
</xsl:for-each>
</card>
<xsl:for-each select="News/Item">
<card id="{generate-id(.)}" title="Pineapplesoft Daily">
<p align="center"><b><xsl:value-of select="Title"/></b></p>
<p><small>by <xsl:value-of select="Author"/></small></p>
<p><xsl:value-of select="Abstract"/></p>
<p><small><anchor>More News...<go
href="#toc"/></anchor></small></p>
<xsl:for-each select="Para">
<p><xsl:value-of select="."/></p>
</xsl:for-each>
<p><anchor>More News...<go href="#toc"/></anchor></p>
</card>
</xsl:for-each>
</wml>
</xsl:template>
Unlike Listing 4.5, this style sheet generates an XML document. Indeed, WML follows the XML syntax. The style sheet also issues a DOCTYPE statement, as required by the WML specification. Figure 4.8 shows the result in a WAP browser. Figure 4.8 The WML document in a WAP browser. RSS Style SheetThe last style sheet is in Listing 4.7. This style sheet generates an RSS document. Unlike the previous two style sheets, this one limits itself to a table of contentsyou will recall that RSS is not designed to handle large documents. RSS is essentially a table of contents of the portal Web site. Listing 4.7 rss.xsl<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output
method="xml"
doctype-public="-//Netscape Communications//DTD RSS 0.91//EN"
doctype-system="http://my.netscape.com/publish/formats/rss-0.91.dtd"/>
<xsl:template match="/">
<rss version="0.91"><channel>
<title>Pineapplesoft Daily</title>
<description>Your source for technology news, trends and
facts of interest to web developers.</description>
<link>http://www.pineapplesoft.com</link>
<language>en</language>
<xsl:for-each select="News/Item">
<item>
<title><xsl:value-of select="Title"/></title>
<link><xsl:value-of select="/News/URL"/>#<xsl:value-of
select="generate-id(.)"/></link>
<description><xsl:value-of select="Abstract"/></description>
</item>
</xsl:for-each>
</channel></rss>
</xsl:template>
Figure 4.9 illustrates the result with My Userland, an RSS portal. ![]() Figure 4.9 Registering the RSS file on My Userland. Building and Running the ProjectThe publishing project is available on a CD-ROM included with the book. Copy the project directory from the CD-ROM to your hard disk. Under Windows, start the server by double-clicking publish.bat. Next, open a browser and type the following URL (refer to Figure 4.7 above): http://localhost:8080/publish If possible, you should download at least one WAP browser and test the document again. You also might want to register the RSS channel with a portal.
If you develop your own documents, register the corresponding RSS channels with http://www.xmltree.com, my.netscape.com, and my.userland.com. Additional ResourcesIf you find this project useful, be sure you read Chapter 8 as well. Chapter 8 presents a different twist on the same technique and many useful extensions to the servlet. DocBookAs has already been indicated, for more complex documents, you can turn to the DocBook DTD available from http://www.docbook.org. DocBook is a powerful DTD for document publishing and is available in both SGML and XML. XHTMLWML is the most popular markup language for mobile users, but the W3C is working on its own solution. The W3C has developed XHTML, an XML version of HTML. The recommendation is available from http://www.w3.org/TR/xhtml1. The major advantage of XHTML is that it is based on HTML so it will be familiar for Web designers. The major inconvenience of XHTML is also that it is based on HTML. This results in a large and complex markup language. Therefore, XHTML currently is too complex for mobile phones. The W3C is working to simplify XHTML. Only time will tell whether XHTML will achieve widespread acceptance. Open eBookAnother interesting format for mobile users is the Open eBook specification. Open eBook was designed for eBook, a different group of mobile users. An eBook can take many forms, but it is generally a palm-sized device on which readers download books. You will find more information on Open eBook from the Open eBook Forum at http://www.openebook.org. A popular eBook reader is the Rocket eBook, available from http://www.rocketebook.com. Unfortunately, it does not support the Open eBook format yet. ICEI introduced RSS as the content syndication format in this chapter because RSS is very popular. RSS is not the only choice, however. An alternative is ICE (Information Content and Exchange protocol). ICE is a more ambitious project that aims to link content providers and publishers. You can find more information on ICE at http://www.w3.org/TR/NOTE-ice. Copyright Sams Publishing. All rights reserved. |
| Suits | Ponytails | Propheads | Contact WDJ | Discuss | Web Audio | Search |