This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XSLT 2.0 Saxon 91 Instantiation How-to Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XSLT 2.0 Saxon 91 Instantiation How-to " Watch "XSLT 2.0 Saxon 91 Instantiation How-to " New topic

XSLT 2.0 Saxon 91 Instantiation How-to

Jack Bush
Ranch Hand

Joined: Oct 20, 2006
Posts: 235
Hi All,

I came across the following minor stumbling block when trying to instantiate Saxon directly as opposed to searching through CLASSPATH recommended by yourself earlier:

( i ) Replaced [b]import javax.xml.transform.* [/b]with [b]net.sf.saxon.TransformerFactoryImpl[/b].
( ii ) Replaced [b]TransformerFactory stateFactory = TransformerFactory.newInstance() [/b]with
[b]net.sf.saxon.TransformerFactoryImpl hobbiesTransformer = new net.sf.saxon.TransformerFactoryImpl()[/b].

FileInputStream hobbiesStyleSheetIS = new FileInputStream(hobbiesStyleSheet);
BufferedInputStream hobbiesStyleSheetBIS = new BufferedInputStream(hobbiesStyleSheetIS);
( iii ) Replaced [b]Transformer hobbiesTransformer = hobbiesFactory.newTransformer(new StreamSource(hobbiesStyleSheetBIS)) [/b]with
[b]hobbiesTransformer.newTransformer(new StreamSource(hobbiesStyleSheetBIS))[/b].

// Run the transformation
JDOMSource hobbiesSource = new JDOMSource(hobbiesOriginaljdomDocument);
JDOMResult hobbiesResult = new JDOMResult();

// Run the transformation
( iv ) Would like to replace [b]hobbiesTransformer.transform(hobbiesSource, hobbiesResult) [/b]with
[b]stateTransformer.? [/b]but couldn't find a match.

In other word, I couldn't find an equivalent statement in Saxon91 to do the transformation in step ( iv ) to swap out the default Java Xalan code.

This question has been posted at [url] [/url]& other XML related sites without constructive response.

Thanks a lot for your help,

Carey Evans
Ranch Hand

Joined: May 27, 2008
Posts: 225

Hi Jack.

Saxon's net.sf.saxon.TransformerFactoryImpl returns an instance of net.sf.saxon.Controller, which implements javax.xml.transform.Transformer, so you should just be able to call its transform() method as usual. Can you provide a self-contained example (in [code] tags) of what you are trying to get working?
Paul Clapham

Joined: Oct 14, 2005
Posts: 18541

Carey, if I'm not mistaken, Jack got an answer from Michael Kay on the Saxon mailing list (one of those other sites which he mentioned). He must have forgotten to follow up here.
I agree. Here's the link:
subject: XSLT 2.0 Saxon 91 Instantiation How-to
Similar Threads
XSLT 2.o : to Use <matches> tag
XMLHttpRequest messes up responseText
Problem with XML to CSV transformation using JDOM api Invalid byte 1 of 1-byte UTF-8 sequence in JDOM SaxBuilder
Simple XSL transformation