Abbey Workshop

Ant: Performing XSLT Tranformations

Apache Ant Java build tool is normally used to build Java programs. However, it also includes a task for performing XSLT Transformations. The transformation task can be applied to a single file, a directory, or an entire directory tree. Being able to transform many files at the same time is a very useful and powerful feature.

Transforming a Single File

To setup a tranformation of a single file, you must specify an input XML file, desired output file, and the stylesheet to be used to perform the transformation. This information is specified in an Ant target using the Xslt Ant task. The following build file will be use in this example and all the examples that follow.

build.xml

Download source for: build.xml

The XML code for the TransformFile target is pretty straightforward. As stated before, specify the input, output, and stylesheet. Running the Ant script transforms the XML file into an HTML document.

Transforming Multiple Files

Ant can also be used to transform a number of XML files with a single stylesheet. Lines 8-14 shows a target that will transform all the files in the current directory tree. Notice that in the includes attribute *.ext.xml is used to specify the files for transformation instead of *.xml. This is a trick to avoid tranforming control files like build.xml. Since a directory tree may contain any number of XML course or control files, you want to be specific about which files are transformed. Therefore, adding an extension before the .xml extension makes the transformation specific to certain class of XML files.

Of course, if the files are in a separate directory you can use the basedir and destdir attributes to keep the XML files and transformation output in different directories. In this example, everything is done in the same directory as the build.xml file. Using the Ant task in this way will produce files with a .ext.html extention. The HTML files have the same prepended file name as the name before .ext.xml files.

Click here to get the student_directory.xml and the student_html.xsl files.

Google
  Web abbeyworkshop.com   

Copyright © Abbey Workshop 2006

Music Only Search
The Black MP3 Album
The MP3 Album Lyrics
Wprld Music Plus
Mp3 Songs Blog
Music Search Store
First Music Search
Mega MP3 Blog
E MP3 BLog
My MP3 Diary
Fast MP3 Finder
My Blog MP3
Mp3 Songs Mart
My MP3 Songs Album
Top Music Group
Mp3 Tune Records
Song Album Guide
Music DataDite
MP3 Buying Guide
Top MP3 Downloads
MP3 Tune Festival
FAST MP3 Downloads
MP3 Mart Online
Upper MP3
Premium MP3 Site
Music Data online
Fine MP3 Audio
Cheap Music Albums
Fine mp3 downloads
World MP3 Music Records
Mp3 Music Data Direct
The Fine Mp3
MP3 Files World
Home Music Store
DatMP3
Fat MP3 Audio
MP3 ZigZag
MP3 Songs Direct
MP3 Tune World
E MP3 Log
Boom MP3 Music
Speedy MP3
Top 20 MP3 music
Deep MP3 World
Deep MP3 Download
Best-20 MP3
Top Twenty MP3
Deep MP3
Big MP3 Guide
Deep MP3 Audio
Mp3 R.O.B.
MP3-Pop Online
Greate-20-MP3
MP3 Appear
3T-MP3