spacer

Webref WebRef   Sitemap · Experts · Tools · Services · Newsletters · About i.com

home / experts / xml / column15

Transforming RSS into HTML and WAP I

A Java Servlet

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume
Developer News
News Flash: Adobe Has iPhone Workaround
Adobe's Flash 10.1 Goes Mobile (Minus iPhone)
A Salute to Visionary CEOs


So what solution offers the best combination of portability and power? In many cases, the answer is Java servlets. Java servlets combine the advantages of a server-based solution with the qualities of Java. They are platform-independent, easy to integrate with existing Web servers, and there are many XML tools written in Java. Popular tools include:

On the following pages we used the LotusXSL processor to develop an XSL style sheet that turns RSS into HTML. We start with a shortened version of this column's RSS:

<rss> 
  <channel> 
    <title>eXploringXML</title> 
    <link>http://exploringxml.com</link> 
    <description>Free tutorials, examples, and tools for XML 
	  at WebReference</description> 
  </channel> 
  <image> 
    <title>eXploringXML</title> 
    <url>http://webref.com/xml/art/logo.gif</url> 
    <link>http://exploringxml.com</link> 
  </image> 
  <item>
    <title>Registering and publishing with RSS</title>
    <link>http://webref.com/xml/column14/</link>
  </item>
  <item>
    <title>Creating RSS files for your Web site</title>
    <link>http://webref.com/xml/column13/</link>
  </item>
</rss> 

The HTML output should look like this:

eXploringXML
Registering and publishing with RSS
Creating RSS files for your Web site

Next we develop the XSL style sheet step-by-step. First we need to set up the HTML page:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/XSL/Transform/1.0">
  <xsl:output method="html"/>

  <xsl:template match="/">
    <HTML><BODY><TABLE BORDER="1">
      <xsl:apply-templates/>
    </TABLE></BODY></HTML>
  </xsl:template>

Then we generate a table header row for the <channel> element:

  <xsl:template match="channel">
    <TR><TH><A>
      <xsl:attribute name="HREF">
        <xsl:value-of select="link"/>
      </xsl:attribute>
      <xsl:value-of select="title"/>
      </A></TH></TR>
      <xsl:apply-templates/>
  </xsl:template>

Next a normal table row for each <item> element:

  <xsl:template match="item">
    <TR><TD><A>
      <xsl:attribute name="HREF">
        <xsl:value-of select="link"/>
      </xsl:attribute>
      <xsl:value-of select="title"/>
      </A></TD></TR>
      <xsl:apply-templates/>
  </xsl:template>

Finally we need to suppress the default text output and close the style sheet:

  <xsl:template match="text()"/>

</xsl:stylesheet>

That is all for now. Of course the output is neither pretty nor customizable but we will improve on this soon. Furthermore, we will show how to adapt this solution to output WAP WML.

Conclusion

There are many ways to process XML content such as RSS files. A servlet-based architecture avoids most of the shortcomings of other solutions, such as limited portability and non-standard libraries. In one of the next installments we will look at how to build a XML Java servlet toolkit that can be used with the most popular Web servers out there.

http://www.internet.com

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Reprints, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Building a Banking Application Home Page with OOP · Mixing Scripting Languages · Review: phpFox, a Social Networking CMS with all the Bells and Whistles
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Enterprise 2.0: Social Networking in the Cloud · BroadSoft Marketplace Hastens Pace of Telephony Innovation · Review: HTC Hero for Sprint

Produced by Michael Claßen
All Rights Reserved. Legal Notices.

URL: http://www.webreference.com/xml/column15/2.html
Created: Jul 18, 2000
Revised: Jul 18, 2000