XSLT Powers a New Wave of Web Applications
Extensible Stylesheet Language for Transformations (XSLT) is a computing language specialized for mapping XML documents into other XML documents.
Explanation of XSLT is no small ambition. The problem has to do with variety; there are many uses for XSLT, many instances of XSLT engines and many cooperating technologies involved in XSLT application, so it's important to focus on the essentials.
The first XSLT essential is its Extensible Markup Language (XML) base (also see the “Glossary of XSLT Terms” Sidebar). XML is the universal data format designed to encode everything: algorithmic data, programs and documents from purchase orders to biblical translations, in any human language, on any kind of computer and operating system. XML looks like HTML except it's a bit more complicated. In fact, one of XML's design goals is to generalize HTML in a way that preserves the comfort of HTML adepts. There's even a flavor of XML called XHTML that permits direct interpretation as HTML. Linux Journal frequently publishes articles on different aspects of XML.
A fully XML-ized world is a simpler one, in many ways. To analyze the operation of an accounts payable department, for example, you don't need to know who reports to whom, who is due for a three-week vacation and all those other messy human details. If you can draw a diagram that shows invoices coming in and payments going out, perhaps with authorization records spawned along the way, then you have abstracted what ought to be the essential information.
This is an intoxicating insight. It promises that a system that can transform one XML document (invoice) into one or more other XML documents (payment check, authorization records) and at least organizes, and possibly solves, all meaningful organization automations. That's why XSLT seems so important now.
Readers with a background in the XML world should generalize their project experience to get a notion of XSLT's true worth. Anyone with practical knowledge of XML knows that it's only the beginning of a solution, not the miracle cure marketing brochures often make it out to be. XSLT is exactly the same: a useful and even powerful way to organize the real work of engineering applications fit for production. The idea of transforming XML documents is an important one; to see whether it's the right idea requires close attention to the technical details.
To start you on your XSLT career and help you get the proper feel for the language, you'll need an engine, or language processor, of your own. The most widely used are based on Java and/or are proprietary. These often are integrated into larger server products: database servers, application servers and so on.
Rather than any of these, this article presents its examples in terms of the tDOM engine. tDOM has several advantages, among which the most important are that it's available under a liberal open-source license, it's exceptionally thrifty on memory and twice as fast as competing XSLT engines in our benchmarks, its installation is quick and compact and it exposes a scriptable command mode that's convenient for instruction. Moreover, tDOM fits well in the dual-level programming style explained below, and it's robust enough to be in production use at several demanding sites already.
To set up your own copy of tDOM, see the “How to Start XSLT Programming” Sidebar. That Sidebar concludes with a first example of XSLT use, invoked as
tclsh8.3 xslt.tcl example1.xml example1.xsl example1.html
This command line says, “Use version 8.3 of the Tcl interpreter to launch the xslt.tcl program. The xslt.tcl utility applies the example1.xsl stylesheet to the example1.xml document and produces example1.html as its output.”
Look at this first as a machine that takes example1.xml as its input and produces example1.html, which has only a couple of lines:
<?xml version="1.0"?> <datum>first message</datum>
Think of example1.html as an expansion of this into well-formatted HTML:
<html><body><h1>first message</h1></body></html>
If all you need is a simple HTML document like example1.html, you can write it directly or use a lightweight macro language, rather than learn XSLT. The value of XSLT begins to appear when you look at more complex examples. You can set up the XSLT transformation to generate example1.html output in a particular style, perhaps with approved fonts or boilerplate site hyperlinks and disclaimers.
XSLT uses the language of stylesheets to specify these transformations. While stylesheets were in use before XSLT's invention, this article ignores other uses and consistently abbreviates XSLT stylesheet as just stylesheet.
On one level, a stylesheet is a program. Just as
int main()
{
puts("Hello.");
}
is the source for a C program, a stylesheet is the source for an XSLT program. A peculiarity of stylesheets, though, is that they are themselves XML documents. Rather than looking like normal computer programs (in the way C, Java and ksh do, say), XSLT source is a kind of markup text (see Listing 1).
With a verboseness typical of XML, this says, roughly, “act as a program that pulls out <datum> elements and puts their contents in <h1> headings of well-formatted HTML.” That's how example1.html is generated.
The application that implements this XSLT interpretation is itself a Tcl program. There's little you need to learn about Tcl at this point. tDOM exposes its XSLT engine with Tcl bindings, and the xslt.tcl script simply treats command-line variables as the filenames of XML documents and passes them on to the engine.
Let's review the example invocation. In
tclsh8.3 xslt.tcl example1.xml example1.xsl example1.html
tclsh8.3 is the name of the executable program we're launching, and xslt.tcl is a minimal Tcl script that wraps the tDOM XSLT engine. If we wanted to improve the error handling of this utility, refinement of xslt.tcl would be the natural place to start.
Running xslt.tcl creates an XSLT processor that receives three filenames. The example1.xml file is a sample XML source document. This file names the stylesheet we apply to example1.xml. The process writes the resulting output document to example1.html. Select different logical contents for example1.html by naming a different XML source, perhaps example2.xml. To change the style of the output, rewrite example1.xsl.
You've now successfully run an XSLT program. All that's left to learn are the details of XSLT as a language and how it's applied to real-world problems. Before more on the syntax and semantics of XSLT, let's look at its uses.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Designing Electronics with Linux | May 22, 2013 |
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
- Designing Electronics with Linux
- New Products
- Linux Systems Administrator
- Senior Perl Developer
- Technical Support Rep
- UX Designer
- Web & UI Developer (JavaScript & j Query)
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Dynamic DNS—an Object Lesson in Problem Solving
- Using Salt Stack and Vagrant for Drupal Development
- Reply to comment | Linux Journal
7 hours 51 min ago - Dynamic DNS
8 hours 25 min ago - Reply to comment | Linux Journal
9 hours 23 min ago - Reply to comment | Linux Journal
10 hours 13 min ago - Not free anymore
14 hours 15 min ago - Great
18 hours 2 min ago - Reply to comment | Linux Journal
18 hours 10 min ago - Understanding the Linux Kernel
20 hours 25 min ago - General
22 hours 55 min ago - Kernel Problem
1 day 8 hours ago
Enter to Win an Adafruit Pi Cobbler Breakout Kit for Raspberry Pi

It's Raspberry Pi month at Linux Journal. Each week in May, Adafruit will be giving away a Pi-related prize to a lucky, randomly drawn LJ reader. Winners will be announced weekly.
Fill out the fields below to enter to win this week's prize-- a Pi Cobbler Breakout Kit for Raspberry Pi.
Congratulations to our winners so far:
- 5-8-13, Pi Starter Pack: Jack Davis
- 5-15-13, Pi Model B 512MB RAM: Patrick Dunn
- 5-21-13, Prototyping Pi Plate Kit: Philip Kirby
- Next winner announced on 5-27-13!
Featured Jobs
| Linux Systems Administrator | Houston and Austin, Texas | Host Gator |
| Senior Perl Developer | Austin, Texas | Host Gator |
| Technical Support Rep | Houston and Austin, Texas | Host Gator |
| UX Designer | Austin, Texas | Host Gator |
| Web & UI Developer (JavaScript & j Query) | Austin, Texas | Host Gator |
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?




Comments
Re: XSLT Powers a New Wave of Web Applications
While this article is an interesting introduction, I am very surprised that it would manage to not even mention libxslt which is probably one of the fastest, most reliable, and most frequently deployed processors, and AxKit which is similar to Cocoon in various ways, but less overdesigned and implemented within Apache using a powerful combination of C and Perl. Both are extremely succesful projects, with constantly growing user bases.
As for XSLT being more used by Tcl and Java folks than by Perl, Python, and C folks I think that's simply wrong, and is no more than an impression gathered from an incomplete sample.
Finally, as the author mentions benchmarks it would be nice to see them! I have no doubt that tDOM beats any pure Java XSLT processor flat, but what of the others? Beating libxslt (both for memory and for speed) appears to me to be a tough task. Even if tDOM were faster, I very much doubt it would be "twice as fast" as claimed rather boldly in this article.
Mod_xslt - ultimate XSLT engine for the web
Check out http://freshmeat.net/projects/mod_xslt_ln/
and http://linuxnews.pl as an example of XML/XSLT technology.
With the mod_xslt you can for example pass the arguments to the XSLT programs.
Example of this is forum system on Linuxnews.pl
regards,
Pumpkin
mod_xobjex for Apache 1.3.x uses libxslt
Similar to mod_xslt, mod_xobjex is a lighter, faster alternative that uses Daniel Veillard's libxslt (which is blazingly fast). With mod_xobjex, web applications are built with pure XSLT. mod_xobjex converts the HTTP Request into XML to which the requested XSL template is applied. Download it at xobjex.com.
XSLT, DOM, SQL and the web
This paper may be of interest to those looking to publish data from relational databases on the net using XSLT.
Re: XSLT Powers a New Wave of Web Applications
www.zvon.org hosts an excellent XSLT reference - a lot easier than reading the W3C documents :-)
If you just want to try out some XSLT examples, here's (http://www.julien-dubois.com) a server-side XSLT transformer, so that you don't need anything on your PC to get you started.
Re: XSLT Powers a New Wave of Web Applications
The "How To Start XSLT Programming" link mentions the 0.63 code snap shot. The xslt engine in tDOM-0.7test is much improoved in XSLT compliance. Grab it from
http://sdf.lonestar.org/~loewerj/tdom.cgi
rolf ade
Re: XSLT Powers a New Wave of Web Applications
And for those who want a fast and compliant XSLT
engine, use xsltproc available from the libxslt package on
most distributions. It is used by KDE and Gnome to generate
the HTML version of their DocBook docs.
Check the web page
and download area for further
informations, packages and the source !
Daniel Veillard
Re: XSLT Powers a New Wave of Web Applications
Yes! Daniel Veillard's libraries and utilities are definitely the way to go for production-quality work with XSLT; they chew through huge groves with speed. It's a true open-source success and deserves more appreciation.
If you're interested in tracking XSLT's growth and maturation, check out the newest version of Michael Kay's SAXON - larger, slower, but also very cool.
Paul Ford
Re: XSLT Powers a New Wave of Web Applications
The way I got started with XSLT was Sablotron; which is available here.. If you use perl, it is nice because it's a perl module; and it also has a command line vesion similar to the tcl command mentioned above. You don't need TCL though; just configure && make && make install.