It's not the DocumentBuilderFactory you need to switch, it's the TransformerFactory.
 
You could load the stylesheet document into a DOM, read the version attribute, and then compile the stylesheet using the appropriate TransformerFactory. Both products will accept the stylesheet from a DOMSource, which saves you parsing it twice - though you may find that you lose line numbers which isn't nice for error messages. I would suggest instantiating the TransformerFactory directly rather than relying on the JAXP mechanisms - that's
 
TransformerFactory tf = new net.sf.saxon.TransformerFactoryImpl()
 
in the case of Saxon; you'll have to find out what the class name is for Xalan.
 
Michael Kay
http://www.saxonica.com/


From: Todd Gochenour [mailto:todd.gochenour@gmail.com]
Sent: 07 April 2009 22:29
To: saxon-help@lists.sourceforge.net
Subject: [saxon] Using both Saxon and Xalan

Is it possible to access the Xalan transformation engine for version 1.0 stylesheets and the Saxon transformation engine for version 2.0 stylesheets.  I have an existing implementation running 1.0 stylesheets in Xalan.  I need to add support for version 2.0 stylesheets using Saxon while keeping the Xalan 1.0 support intact. 
 
Do I need to open the stylesheet file, access the stylesheet version, and then access either the class net.sf.saxon.dom.DocumentBuilderFactoryImpl() or the class org.apache.crimson.jaxp.DocumentBuilderFactoryImpl() depending on the stylesheet version?  
 
Everything I've read so far regarding TrAX and JAXP is how to configure a system property to reference one or the other engine to run in the Java process. 
 
Is there a recommended strategy?
 
Todd Gochenour