Introduction
This is the second in a multi-part series detailing the benefits of using XSL Transformations (XSLT). The first tutorial introduced you to the MindMap Research Team, which uses XSLT as part of its analytical toolbox for interpreting data related to cognitive processes. The goal is to give their clients maximum control over their data by leveraging the ability to change algorithms and methods without having to recompile applications. The MindMap team deals with several aspects of the process, from data acquisition to visualization to tying the data in to other resources.
This tutorial is designed for programmers who want to change the criteria of an XSL transformation on the fly by using forms to send parameter values through the XSLT. For example, a user could search for a specific item in the XML document by simply entering a search string into a text box using pure XSLT and some application logic either on the server or through a browser's API. If you haven't heard of this kind of activity using XSLT, you can be sure that other people have. Microsoft, in fact, has created a new Office family member named InfoPath to accomplish the same thing. As an XSLT developer, you can forego the costs of InfoPath and simply create your own InfoPath-like applications. So if you're interested in making genuinely dynamic, forms-based XML applications, read on.
You should have a basic understanding of XSLT and XML before
you take this tutorial. In other words, if you aren't familiar with what an
XSLT parameter does and how it works, you'll find some of this material a
little difficult. This is because this tutorial keys in on the use of the
xsl:param element as you learn how to pass parameters
from forms through your stylesheets. You'll also see a fairly significant amount of
JavaScript as well, but you can probably get by with the most
basic understanding of that language and copy and paste the code you see here,
with some customization that I'll walk you through. The same holds true for the
Document Object Model (DOM), which is the object model used by JavaScript to
access XML nodes for manipulation. You don't need to be a DOM expert to work
with this tutorial -- I provide enough of a conceptual overview of the DOM that
you should be able to work the examples and move ahead on your own after you have
finished.
You may recall the MindMap team from the first tutorial, but if you don't remember this motivated crew of XSLT maniacs, or if you haven't yet read the first tutorial, a brief reintroduction is in order. MindMap is a fictional research team that works extensively to help university researchers efficiently collect and analyze data. The MindMap team, which has many gigabytes of research articles in their archives, decided to use a process it calls Dynamic XSLT to create a search engine, which the team can port to many different kinds of documents.
One of the first things they leveraged against was the fact that the xsl:param element is a
hardy tool for processing XSLT from the server and creating interactions with Web forms. It allows users
to supply values through name/value pairs and process nodes based on those values. This means you can
call different templates dynamically on the client based on user input to display different sets of
data based on user events.
The team realized that you can do the same sort of thing on the client side in Mozilla-based browsers such as Netscape 7.0 and in Internet Explorer 5.0 and higher. This allowed them to create XSLT-based applications that required nothing more than a browser to work effectively, no matter what kind of IT environment their clients were using.
I could have chosen a server technology to demonstrate the same concepts -- that of passing parameters to and from a stylesheet to change the search context -- but I like the MindMap approach because anyone can use it. You don't need access to a Web server to work with this tutorial. All you need is the willingness to download and install Netscape or Mozilla. You'll see that an API for working with XML data is an API, whether it's client-side or server-side, and that the key is managing the object methods and properties of whatever API you're using to make a transformation dynamic.
In this tutorial, you'll use XSLT to accomplish the following:
- Create the necessary HTML form fields
- Build named templates for analyzing properties
- Pass parameters to the templates
- Build a user interface to let users change the algorithm parameters
- Handle the parameters in your application code
Make sure you install and test the following tools before beginning the tutorial:
- Mozilla 1.2 or higher. Download it from http://www.mozilla.org/.
- A text editor that supports UTF-8 (http://www.cl.cam.ac.uk/~mgk25/unicode.html) or an XML editor (http://www.garshol.priv.no/download/xmltools/cat_ix.html#SC_XMLEditors).
Finally, you'll want to download the files referred to throughout this tutorial in file x-analysfiles.zip. You should download them before starting the tutorial so that you can follow along more easily, because you'll often encounter code fragments taken from longer files and it helps to view those fragments in the context of the overall file.

