Wednesday 6 June 2007

Simple Saxon Java example

I'd been wanting to create the *simplest* class possible to enable me to transform xsl files within a java application.

I looked around for a really simple example of this process. After a bit of digging around, I "ripped" these bits from the very comprehensive TraxExamples.java file provided within saxon-resources8-9.zip (the original file authored by Scott Boag) and now I have a class containing something like this:



The "void main" bit:



For this to work, you can get the real handleException method from the TraxExamples.java, or for the minimal amount of code to make it work (and not necessarily to make it too useful):



Using eclipse, all the imports were pulled in via Source > Organize Imports (Ctrl + Shift + O)

Does the trick for me :)

14 comments:

bpk said...

I spent atleast an hour trying to find out how to tell java I wanted to use the saxon processor and I landed on your blog. Thanks a lot. Cheers

Javucho said...

Thanks!

maxbuttlies said...

Good work, thanks!

conorgaff said...

Also, in eclipse remember to add the saxon.jar to runtime classpath. (couldn't figure out why it wasn't working until I realized...)

Mike Quentel said...

Thanks for this excellent example.

DM said...

An excellent simple example that works for me, thanks very much! :-)

Vignesh said...

Hi, i am converting html file to xml using xslt and saxon.How to modify the above code..please help.

Victorious said...

I was just about to rollback two days of work when I saw this. Thanks you are a life saver. Or at least a time saver. :)

/Victor

Auz said...

Nice article, thanks!

Mauricio Murillo said...

Thank, nice post!!! It really helps me.

Mauricio Murillo said...

Thanks, nice post!!! It really helps me.

John Ortiz OrdoƱez said...

Do you know how to extract attributes values from an element. For example:



Thanks in advance for your help.

So long.

Unknown said...

Thank you. It very helpful for me.

Unknown said...
This comment has been removed by the author.