RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Using XTags to Add XSLT Transformations to Your JSP Web Applications

You don't have to write repetitive manual code to display database tables or apply transformations to display XML documents in your JSP Web applications; the Jakarta XTags tag library provides an easy way to apply an XSLT stylesheet to XML data.

oday's applications often use XML technology to represent and transfer structured data. You can display the data in an XML document as HTML by applying an XSLT stylesheet transformation to the XML data. In a Java application, you perform the XML-to-HTML transformation by writing code that uses the javax.xml.transform package API. In a JSP Web application you can perform such transformations with a tag library called XTags that supports XSLT and XPath. Although you can use XML documents directly as a datasource, the preferred datasource for Web applications is a relational database (RDBMS). In a typical three-tier Web application the database provides the data storage, a middle tier application provides the conversion of database data to XML, and a client application such as a JSP or a JSF presents the data as HTML by applying an XSLT transformation.

In this article you'll see how to develop a Web application that retrieves data from an Oracle database, converts it to XML with the Oracle XML SQL Utility (XSU), and presents the data as HTML via a JSP by applying an XSLT transformation. You can also apply CSS stylesheets in a JSP.

I've used WebLogic 8.1 as the application server, obtaining data via a JNDI datasource and a JDBC connection with the database, using the Apache Jakarta XTags tag library to perform the XSLT transformations. XTags supports both XSLT (transformation) and XPath (XML search/retrieval) within JSP pages. The example modifies the database table before displaying to the user as HTML.

Preliminary Setup
Follow these steps to prepare your development machine to run the example.

  1. Download and install WebLogic Server 8.1.
  2. Download and install Oracle 10g, including the sample schemas. Create an Oracle database instance, "OracleDB" for example. Create an example database table named Catalog, in the OE schema. Here's an SQL script you can use to create and populate the table.
  3.    CREATE TABLE OE.Catalog(CatalogId VARCHAR(25), 
          Journal VARCHAR(25), Publisher Varchar(25), 
          Edition VARCHAR(25), Title Varchar(45), Author Varchar(25));
       INSERT INTO Catalog VALUES('catalog1', 'Oracle Magazine',
          'Oracle Publishing', 'March-April 2005', 
          'Starting with Oracle ADF', 'Steve Muench');
       INSERT INTO Catalog VALUES('catalog2', 'Oracle Magazine', 
          'Oracle Publishing', 'March-April 2005', 
          'Aggregate Data with XQuery', 'Nilesh Junnarkar');
       INSERT INTO Catalog VALUES('catalog3', 'Oracle Magazine', 
          'Oracle Publishing', 'July-August 2005', 
          'Tuning Undo Tablespace', 'Kimberly Floss');

  4. Download the Apache Jakarta XTags tag library and extract the zip file to a directory.
  5. XTags is based on the dom4j XPath framework. Download dom4j and extract the zip file to a directory.
  6. Download the Xalan XSLT implementation.
  7. Download XDK 10g.
To finish the setup, add the following files to your CLASSPATH where <XDK> is the directory where you installed XDK 10g Production, and <Oracle10g> is the directory in which you installed Oracle Database 10g.

  • <XDK>/lib/xsu12.jar
  • <XDK>/lib/xmlparserv2.jar
  • <XDK>/lib/xdb.jar
  • <Oracle10g>/LIB/servlet.jar
  • <Oracle10g>/jdbc/lib/classes12dms.jar

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