Skip to main content

By clicking Submit, you agree to the developerWorks terms of use.

The first time you sign into developerWorks, a profile is created for you. Select information in your developerWorks profile is displayed to the public, but you may edit the information at any time. Your first name, last name (unless you choose to hide them), and display name will accompany the content that you post.

All information submitted is secure.

  • Close [x]

The first time you sign in to developerWorks, a profile is created for you, so you need to choose a display name. Your display name accompanies the content you post on developerworks.

Please choose a display name between 3-31 characters. Your display name must be unique in the developerWorks community and should not be your email address for privacy reasons.

By clicking Submit, you agree to the developerWorks terms of use.

All information submitted is secure.

  • Close [x]

Manipulating data with XSL

Make changes to database contents without stored procedures

Nicholas Chase has been involved in Web site development for companies including Lucent Technologies, Sun Microsystems, Oracle Corporation, and the Tampa Bay Buccaneers. Nick has been a high school physics teacher, a low-level radioactive waste facility manager, an online science fiction magazine editor, a multimedia engineer, and an Oracle instructor. More recently, he was the Chief Technology Officer of Site Dynamics Interactive Communications in Clearwater, Fla. He is the author of three books on Web development, including the upcoming XML Programming Primer Plus (Sams). He loves to hear from readers and can be reached at nicholas@nicholaschase.com.

Summary:  What happens if you need to manipulate data in a database, but you can't create stored procedures? You pull the information, manipulate it, and put it back, that's what. One way to conveniently do that is to retrieve the data into XML structures and then use XSL to manipulate it. This tutorial teaches you to use XSLT to manipulate data that has been pulled from a database and then restore it to the database. Examples are in Java, but the principles apply in other languages.

Date:  24 Oct 2001
Level:  Intermediate PDF:  A4 and Letter (602 KB | 34 pages)Get Adobe® Reader®

Activity:  8504 views
Comments:  

Introduction

Should I take this tutorial?

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).


What is this tutorial about?

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.


Tools

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.transform package 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 monospace font. 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 monospace font is used for file and path names.
  • Throughout this tutorial, code segments irrelevant to the discussion have been omitted and replaced with ellipses (...)

1 of 10 | Next

Comments



Help: Update or add to My dW interests

What's this?

This little timesaver lets you update your My developerWorks profile with just one click! The general subject of this content (AIX and UNIX, Information Management, Lotus, Rational, Tivoli, WebSphere, Java, Linux, Open source, SOA and Web services, Web development, or XML) will be added to the interests section of your profile, if it's not there already. You only need to be logged in to My developerWorks.

And what's the point of adding your interests to your profile? That's how you find other users with the same interests as yours, and see what they're reading and contributing to the community. Your interests also help us recommend relevant developerWorks content to you.

View your My developerWorks profile

Return from help

Help: Remove from My dW interests

What's this?

Removing this interest does not alter your profile, but rather removes this piece of content from a list of all content for which you've indicated interest. In a future enhancement to My developerWorks, you'll be able to see a record of that content.

View your My developerWorks profile

Return from help

static.content.url=http://www.ibm.com/developerworks/js/artrating/
SITE_ID=1
Zone=XML
ArticleID=138535
TutorialTitle=Manipulating data with XSL
publish-date=10242001
author1-email=nicholas@nicholaschase.com
author1-email-cc=

Tags

Help
Use the search field to find all types of content in My developerWorks with that tag.

Use the slider bar to see more or fewer tags.

Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere).

My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Use the search field to find all types of content in My developerWorks with that tag. Popular tags shows the top tags for this particular content zone (for example, Java technology, Linux, WebSphere). My tags shows your tags for this particular content zone (for example, Java technology, Linux, WebSphere).

Try IBM PureSystems. No charge.