Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


advertisement
 

Supercharge Your Java Web Applications with Translets : Page 2

Translets, a brand new addition to Java, can improve your Web application performance multiple fold. This article walks through the creation of translets, discusses translet functionality, and demonstrates how to use them from within a Java application.


advertisement
Translets in Action
Suppose you have an XML representation of all the employees of a company and your application needs to construct a HTML page for presentation. A simple Java application in this case demonstrates how you can use translets. However, the same concept can be incorporated into the servlets or JSPs of a Web application very easily. The source code download provided with this article contains all the files you need to install and run this sample application, which requires JDK 1.3 or higher. (It also contains a readme.txt file that details the steps for running the demo application.)

The following is the company employee XML:

<?xml version="1.0" encoding="UTF-8"?> <CompanyEmployeeList> <Employee> <employeeName>Mr. Java</employeeName> <designation>programmer</designation> <department>IT</department> <salary>40K</salary> </Employee> <Employee> <employeeName>Mr. Servlets</employeeName> <designation>programmer</designation> <department>IT</department> <salary>45K</salary> </Employee> </CompanyEmployeeList>



The following XSL transforms the above XML into a simple HTML page, displaying the content in a HTML table (These contents are from example.xsl in the source code download):

<xsl:stylesheet version = '1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> <xsl:template match="/"> <table border="1" cellpadding="6"> <tr><th colspan="4">Company Employees</th></tr> <tr> <th>Employee Name</th> <th>Designation</th> <th>Department</th> <th>Salary</th> </tr> <xsl:for-each select="//Employee"> <tr><xsl:call-template name="print"/></tr> </xsl:for-each> </table> </xsl:template> <xsl:template name="print"> <td><xsl:value-of select="employeeName"/></td> <td><xsl:value-of select="designation"/></td> <td><xsl:value-of select="department"/></td> <td><xsl:value-of select="salary"/></td> </xsl:template> </xsl:stylesheet>



Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date