Introduction
This tutorial is designed to assist Java developers who need to manipulate data in a database without the advantage of stored procedures. The tutorial demonstrates how to manipulate database data using XSLT (eXtensible Stylesheet Language Transformation) instead of stored procedures.
This tutorial assumes you are already familiar with the basics of XML in general, the Document Object Model (DOM) in particular, and with the basics of XSLT and XPath. All of the examples use Java, with JDBC for database access, but you can still get a basic grounding in the concepts without trying out the examples.
The links in Resources include referrals to tutorials on XML and DOM basics, XSL and XPath basics, and database access using JDBC (including the basics of SQL).
The examples used throughout this tutorial demonstrate the analysis and conversion of Web access logs stored in a database using XSLT. The application then adds the new data to separate database tables.
This tutorial explains the basics of retrieving data from a database into a DOM document, transforming the DOM document into a second document, and inserting the data from the second document into the database using updatable ResultSets in Java. (Though the examples are all written in Java,
the concepts are the same in any programming language and the tutorial can assist any developer who wants to learn how to manipulate data with XSLT.) Several of the more advanced features of XSLT and XPath are covered, demonstrating some of the ways that XSLT style sheets can be used to emulate the programming capabilities of database stored procedures.
This tutorial will help you understand the topic even if you read the examples rather than trying them out. If you do want to try the examples as you go through this tutorial, make sure you have the following tools installed and working correctly:
- A text editor: XML and Java source files are simply text. To create and read them, a text editor is all you need.
- A Java environment, such as the Java 2 SDK, which is available at http://java.sun.com/j2se/1.3/ or the IBM JDK, which is available at http://www.ibm.com/developerworks/java/jdk/index.html.
- Any database that understands SQL, as long as you have an ODBC or JDBC driver. You can find a searchable list of more than 150 JDBC drivers at http://industry.java.sun.com/products/jdbc/drivers. (If you have an ODBC driver, you can skip this step and use the JDBC-ODBC bridge, which is included as part of the Java 2 SDK.) This tutorial uses JDataConnect, available at http://www.jnetdirect.com/products.php?op=jdataconnect.
- Java APIs for XML Processing, version 1.1 or later. Also known as JAXP, this is the reference implementation that Sun provides. You can download JAXP (you must have version 1.1 or later; the 1.0 release did not include support for XSLT) from
http://java.sun.com/xml/xml_jaxp.html.
This download also includes the Xalan 2 XSL Transformation
engine. You can also download it from http://xml.apache.org/xalan-j/index.html. Xalan is updated more often than JAXP these days, and it also includes the JAXP 1.1.1, so you may prefer to download Xalan Java to obtain a current release of both JAXP and Xalan. If you're not sure whether you have the correct version of JAXP, check to see whether you have the
javax.xml.transformpackage installed; if it's there, you have what you need.
Other XSLT processors:TraX was built in to JAXP beginning with JAXP version 1.1 to provide a simple way for Java developers to choose any XSLT processor without affecting the underlying code. So although the current version of JAXP includes Xalan, you can use a different XSLT processor if you prefer.
Other languages: If you want to adapt the examples, you can download a C++ implementation of Xalan from the Apache Project at http://xml.apache.org/xalan-c/index.html. Similarly, while the examples use TrAX as their transformation methodology, and TrAX is currently available only to Java developers, you can adapt the examples to use a native transformation method in your language of choice and still gain a thorough understanding of the concepts demonstrated in this tutorial.
Conventions used in this tutorial
There are several conventions used in this tutorial to reinforce the material at hand:
- Text that needs to be typed is displayed in a
bold monospacefont. In some code examples, bold is used to draw attention to a tag or element being referenced in the accompanying text. - Emphasis/Italics is used to draw attention to windows, dialog boxes, and feature names.
- A
monospacefont is used for file and path names. - Throughout this tutorial, code segments irrelevant to the discussion have been omitted and replaced with ellipses (
...)

