[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Using Saxon to do XSL transforms in Java program

Subject: Using Saxon to do XSL transforms in Java program
From: "Adam Schweitzer" <adam.schweitzer@xxxxxxxxxxxxx>
Date: Fri, 10 Aug 2007 14:14:49 -0400
 Using Saxon to do XSL transforms in Java program
Hi all,
I'm trying to write a Java program to perform an XSL transform using the
JAXP API.  The relevent code is as follows:

// start code snippet
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
TransformerFactory tFactory = TransformerFactory.newInstance();

DocumentBuilder builder = factory.newDocumentBuilder();
StreamSource stylesheet = new StreamSource(xslFile);
Transformer transformer = tFactory.newTransformer(stylesheet);

doc = builder.parse(xmlFile);
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(outFile);
transformer.transform(source, result);
// end code snippet

Pretty straightforward stuff, I think, and it works fine when using the
default XSL processor.  However, I want to make use of the Saxon 6.5.5
processor, as I am using the saxon:output extension in one of my
stylesheets (don't want to use XSLT 2.0 - and xsl:result-document - as
I've been told some things behave differently).

I add the saxon.jar file to my build path in Eclipse (v3.2.1, using
v1.4.2 of the JDK), and it appears that it finds Saxon OK without
needing to set the javax.xml.parsers.DocumentBuilderFactory or
javax.xml.transform.TransformerFactory properties (I get the same
behaviour either way).  When the program gets to the line:
Transformer transformer = tFactory.newTransformer(stylesheet);

though, an exception occurs (note that nothing has been changed except
adding the saxon.jar to my build path - I remove it, and the program
executes successfully, with the desired results):

javax.xml.transform.TransformerConfigurationException:
java.io.EOFException: no more input
 at
com.icl.saxon.PreparedStyleSheet.prepare(PreparedStyleSheet.java:121)
 at
com.icl.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl
.java:120)
 at
com.icl.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryIm
pl.java:72)
 at DoTranforms.main(DoTranforms.java:28)
Caused by: java.io.EOFException: no more input
 at com.icl.saxon.aelfred.XmlParser.popInput(XmlParser.java:4083)
 at com.icl.saxon.aelfred.XmlParser.pushURL(XmlParser.java:3620)
 at com.icl.saxon.aelfred.XmlParser.doParse(XmlParser.java:159)
 at com.icl.saxon.aelfred.SAXDriver.parse(SAXDriver.java:320)
 at com.icl.saxon.om.Builder.build(Builder.java:265)
 at
com.icl.saxon.PreparedStyleSheet.prepare(PreparedStyleSheet.java:111)
 ... 3 more
---------
java.io.EOFException: no more input
 at com.icl.saxon.aelfred.XmlParser.popInput(XmlParser.java:4083)
 at com.icl.saxon.aelfred.XmlParser.pushURL(XmlParser.java:3620)
 at com.icl.saxon.aelfred.XmlParser.doParse(XmlParser.java:159)
 at com.icl.saxon.aelfred.SAXDriver.parse(SAXDriver.java:320)
 at com.icl.saxon.om.Builder.build(Builder.java:265)
 at
com.icl.saxon.PreparedStyleSheet.prepare(PreparedStyleSheet.java:111)
 at
com.icl.saxon.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl
.java:120)
 at
com.icl.saxon.TransformerFactoryImpl.newTransformer(TransformerFactoryIm
pl.java:72)
 at DoTranforms.main(DoTranforms.java:28)
Exception in thread "main"

Am I missing something here?  I can't figure out why this doesn't work -
when I apply the same stylesheet to the same xml file in Oxygen - using
the same XSL processor - it works fine.. so I'm scratching my head here
a bit.

Cheers,
Adam Schweitzer
Orenda Aerospace Corporation

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.