The Source for Java Technology Collaboration




XML Portlet

Description

The XMLPortlet is a simple portlet that performs an XSL translation on an XML file. The XML and XSL files are specified in the portlet preferences, i.e.:

    <preference>
        <name>xmlFile</name>
        <value>/tmp/sample.xml</value>
    </preference>
    <preference>
        <name>xslFile</name>
        <value>/tmp/sample.xsl</value>
    </preference>

Prerequisites for Deployment

None. The portlet can be directly deployed into any JSR 168 compliant container without any additional configuration.

Deployment Steps

Deploy the portlet to your Portlet Container. For your convenience, the "How To" section on project wiki page will help you get started with a few popular portlet containers.

Tested On

  • Open Source Portlet Container 1.0

Portlet View

Here's an example of the portlet view with the following sample XML and XSL files:

sample.xml

<?xml version="1.0"?>
<tours-data>
<tour-set>
<tour name="Great Barrier Reef" where="Australia" when="May"/>
<tour name="Himalaya Mountaineering" where="Tibetan Plateau region of Northern India" when="June"/>
<tour name="Kitesurfing in Chile" where="The coast of Patagonia, Chile" when="July"/>
<tour name="Mountain Biking in Utah" where="Book Cliffs, Utah" when="August"/>
<tour name="Ocean Kayaking" where="Esperance, Western Australia" when="September"/>
<tour name="Grand Canyon Hike" where="Arizona" when="October"/>
</tour-set>
</tours-data>

sample.xsl

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:template match="/">
<html>
<head>
</head>
<body>
<table bgcolor="#ffffff" cellpadding="2" border="0" cellspacing="0" width="100%">
<tr>
   <th align="left">Tour</th>
   <th align="left">Where</th>
   <th align="left">When</th>
</tr>
<xsl:for-each select="tours-data/tour-set/tour">
<tr>
   <td width="30%" nowrap="yes" align="left"><xsl:value-of select="./@name"/></td>
   <td width="50%" nowrap="yes" align="left"><xsl:value-of select="./@where"/></td>
   <td width="10%" nowrap="yes" align="left"><xsl:value-of select="./@when"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet> 

Topic XMLPortlet . { Edit | Ref-By | Printable | Diffs r1 | More }
 XML java.net RSS

Revision r1 - 20 Oct 2007 - 21:50:00 - Main.tmueller
Parents: WebHome