I need to transform one XML document into another using XSLT (for now from command line). I have to use Java 1.4.2. Based on that someone recommended using Saxon and provided the XSLT. It seems simple it should work, but I am lost.
I come more form a .NET environment, and have worked with XML and XSLT but not with Saxon and I am not that strong in Java.
Let me start by explaining what my problem is and what I have tried so far:
The Error:
C:\Projects\new_saxon_download>java net.sf.saxon.Transform -s:source.xml -xsl:style.xsl -o:output.xml
Exception in thread "main" java.lang.NoClassDefFoundError: org/xml/sax/ext/DefaultHandler2
at net.sf.saxon.Configuration.(Configuration.java:2047)
at net.sf.saxon.Transform.setFactoryConfiguration(Transform.java:81)
at net.sf.saxon.Transform.doTransform(Transform.java:133)
at net.sf.saxon.Transform.main(Transform.java:66)
Steps that led me here:
- I downloaded Saxon-B by following a link from this page
- I also found some information on a dependency about SAX2 from this
page and thus obtained that as well. - Set the CLASSPATH in my session:
set CLASSPATH=.;C:\Projects\new_saxon_download\saxon9.jar;C:\Projects\new_saxon_download\sax2r2.jar
- Tried the transformation:
java net.sf.saxon.Transform -s:source.xml -xsl:style.xsl -o:output.xml
Then I get the error shown above. I have tried multiple google search, but nothing has helped.
Any advice or solution would be very helpful.
GOT IT – the description on how to fix the dependendcy issue is crap (sorry).
This file
sax2r2.jarisn’t the one you have to add to the classpath. It contains another jar (sax.jar) and that’s the library you actually need. Just extract the sax2r2.jar and putsax.jaron the classpath, then it should work.Give this a try: apache xml-commons includes
xml-api.jar. I can’t tell if this is usable with java 1.4.12 but it’s worth a try.Binary releases can be found here. Download one of the xml-commons-external archives, extract xml-api.jar and add that to your classpath.