XSLT Tutorial


Welcome to this XSLT Tutorial. The examples here attempt to teach XSLT through example.

(In reality, these are crib notes I use to help me remember exactly how XSLT works when I need to use it—which ain't often!)

The Tutorial consists of a series of progressively more complex XSLT scripts with notes describing the new aspects of each script (compared to earlier examples). Each script allows you to view the input XML, the output XML or HTML, and–of course–the XSLT script itself.

The Reader is presumed to be familiar with XML, but not XSLT.

XSLT In 25 Words Or Less

XSLT is a standard dialect of XML used to define transformation of an XML input to an output XML (or HTML or Text).

23 words!

It would take a few more words to explain that it requires an XSLT translator or compiler to take an input XSLT script and an input XML document and create the output document.

And it would take even more words to talk about the fact that XSLT is actually a programming language (albeit not your standard type!). Some people believe that XSLT is actually Turing Complete. If this is true (although I believe the jury is still out), then XSLT–in principle–is just as good as Java or C++!

Using XSLT

The examples here use Microsoft's freely available MSXSL.EXE compiler to generate output, however MSIE will perform XSLT transformations when viewing XML documents if the XML includes a stylesheet directive.

This makes it easy to view an XML document as nicely-formatted HTML!

Series 100

The first series demonstrates how to match the XML input document for the template.

It also demonstrates the related principle of select, including the use of “.” and “*”, along with axis selectors such as child:: and decendant::.

Finally, it shows the use of some of the built-in functions, such as name(), position(), last(), etc.

Series 200

The 200 Series demonstrates the use of sub templates to match portions of the input document for processing.

Series 300

The 300 Series focuses on generating HTML from XML input.