Frankly XSLT

Today, Frank asked me for basic xslt and this week Andreas also showed more interest in XSLT than I expected, so I thought I write down some notes on how to get going with XSLT. I won't tell you what XSLT actually is, just info that you might be missing when you start out.

Another thing: One way of using XSLT is to convert xml to html or xhtml; i use it to transform xml data to xml data in another format.

Basic Info on XSLT

  • http://www.w3schools.com/xsl. When I need to look up something quick and don't have a book with me. This is good for the very beginner.
  • The ultimate resource is this book, written by one of the guy's who developed XSLT: Michael Kay. XSLT 2.0 Programmer's Reference, 2nd. edition. Wrox, see here for example. Edit: look for the 3rd edition!
    This book might be a little too difficult for the very beginner, but it's the one book you do not want to have when you are looking for the definite answer.
  • Apart from XSLT you also need something on Xpath, again I started with w3c school.

Two versions of the spec

XSLT is defined in the W3C specification, so the link to the spec should not be missing here, but be warned: it comes in a language you only understand when you already know almost all you need to know about XSLT. Maybe this is also the point where I should tell you that there are two versions of the spec, an old one (version 1) and a new one (version 2.0). XSLT 1.0 is still often used, but 2.0 is much more powerful and I think it's fun, but many processors still only understand 1.0. For me this is the main reason why I use saxon as a xslt processor since it runs XSLT 2.0 without problems.

Further Reading

Most likely, there are many good resources on the web on xslt. You can find yourselves and you can pick what you like, but what I want to show you is how I run a simple xslt transformation on my laptop.

General XSLT Processor choice

I use saxon as XSLT processor. It comes in two versions: one is a commercial license and one is open source. Since only a few months, the two version have new names. The free version is now called Saxon-HE, download it from the homepage. I recommend the to download the java version. Documentation for Saxon. I usually put it in C:\Programme\Saxon, but you can put anywhere where you like it as long as you remember the path.

Java

Obviously, you need java to use the java version. It is not unlikely that you have java already installed, although I didn't before I asked the IT department. For a new version of Saxon you need JDK 1.5 or higher. JRE (java runtime environment) is not enough.

Then it would be in (I am assuming German Windows XP here) C:\Programme\Java

If you can install it yourself (you need administrator rights to run the installer smoothly).

Run the dos box: Hit STRG+R or Start -> Ausführen and type "cmd" in the little windows which opens. Then you should get the black dos window.

Type in

java -version

to check if java is installed.

Use saxon on Command Line?

Follow these instructions from saxon documentation.

I usually make myself a little batch or shell script to saxon which could look like this in bash or similar (see attachment) for dos

#!/usr/bin/bash
java -Xmx256m -jar 'C:\Program Files\saxon\saxonhe9-2-0-6j\saxon9he.jar' $*

I call it saxon or saxon.bat and save it somewhere in path.

What I usually do is

saxon -t -xsl:transformation.xsl input.xml > output.xml

Or GUI?

I like command line.  If you don't, checkout the kernow project.

Editor VS IDE

The the very beginning it is probably okay if you use wordpad.exe to edit xsl and xml files, but as you learn more you will want something more powerful. My favorite IDE for editing xml is oXygen, but it is not free. When I need a free editor I use eclipse. In comparison to oXygen it is more difficult to install, set up and it is considerably slower, but it is a great tool also.

A nice IDE let's you choose the xslt processor of your choice, let's you edit xml and xsl files and with a simple click you run the transformation and get the result. Yet, I use the IDE only for editing my xsl files and prefer the command line for running the transformation, altough that's probably not very efficient.

AttachmentSize
saxon.bat261 bytes
No votes yet
Theme provided by Danetsoft under GPL license from Danang Probo Sayekti