Project

Profile

Help

Newbie: using Saxon 9.1 with FOP .95 (embedde

Added by Anonymous over 15 years ago

Legacy ID: #7181301 Legacy Poster: Francis Parsons (fparsons)

Hi! I have been searching for quite a while for examples on how I would go about using Saxon 9.1 with FOP .95 embedded in a Websphere 5.1.2 application. I have FOP working with Xalan 2.7.0 now, but would like to try Saxon-B - primarily to be able to use XSLT 2.0 features. From searching, all the examples I've seen of saxon+fop show how to set the command line options. I did look at at the examples in the "saxon-resources", but honestly I don't yet understand many of them and/or which would apply to what I'm trying to do. Much of the web results I could find pertain to earlier versions of both Saxon and FOP. The documentation for FOP doesn't seem to have anything on this either. Could some kind-hearted person show me some code and/or instructions? Does anyone have any idea why this information seems so hard to find? --- Francis


Replies (9)

Please register to reply

RE: Newbie: using Saxon 9.1 with FOP .95 (embedde - Added by Anonymous over 15 years ago

Legacy ID: #7181593 Legacy Poster: Michael Kay (mhkay)

It would be useful to know how you are currently running FOP with Xalan, since you will want to make as few changes as possible.

RE: Newbie: using Saxon 9.1 with FOP .95 (embedde - Added by Anonymous over 15 years ago

Legacy ID: #7181794 Legacy Poster: Francis Parsons (fparsons)

Hi! Thanks for the really quick reply! - here's some code below (cut out extraneous bits like logging and error handling). As you can see I pretty much just followed the pattern from the FOP documentation. (My j2ee application is using Spring - I have the code in a "utilImpl" bean. When the bean is created on app startup the FopFactory instance is created) =============================================== public boolean fopPrint(StreamSource doc,StreamSource stylesheet,String outputMimeType,File outputFile){ FOUserAgent foUserAgent = fopFactoryInstance.newFOUserAgent(); foUserAgent.setTargetResolution(200); // Setup output OutputStream out = new java.io.FileOutputStream(outputFile); out = new java.io.BufferedOutputStream(out); try { // Construct fop with desired output format Fop fop = fopFactoryInstance.newFop(outputMimeType, foUserAgent, out); // Setup XSLT TransformerFactory factory = TransformerFactory.newInstance(); Transformer transformer = factory.newTransformer(stylesheet);//<-- StreamSource // Set the value of a <param> in the stylesheet //transformer.setParameter("versionParam", "2.0"); transformer.setParameter("versionParam", "1.0"); // Setup input for XSLT transformation Source src = doc;//<-- StreamSource // Resulting SAX events (the generated FO) must be piped through to FOP Result res = new SAXResult(fop.getDefaultHandler()); // Start XSLT transformation and FOP processing transformer.transform(src, res); } } ================================================ Thanks for any help with this! --- Francis

RE: Newbie: using Saxon 9.1 with FOP .95 (embedde - Added by Anonymous over 15 years ago

Legacy ID: #7181882 Legacy Poster: Michael Kay (mhkay)

The line that selects Xalan is this: TransformerFactory factory = TransformerFactory.newInstance(); If you don't mind a compile-time dependency on Saxon, the most reliable way to change this is: factory = new net.sf.saxon.TransformerFactoryImpl(); Alternative ways are to set the Java system property javax.xml.transform.TransformerFactory, or to arrage the classpath so that Saxon is found first. Or in JDK 1.6, you can use factory = TransformerFactory.newInstance("net.sf.saxon.TransformerFactoryImpl", null);

RE: Newbie: using Saxon 9.1 with FOP .95 (embedde - Added by Anonymous over 15 years ago

Legacy ID: #7181958 Legacy Poster: Francis Parsons (fparsons)

Thanks, I'll give this a try - I was hoping to just put the Saxon jar files in the "lib" location of the application - would there be any potential problems with this? Are any of the jar files "optional" or would I need all 9? Do you know of any issues about using FOP .95 with Saxon that I should look for? --- Francis

RE: Newbie: using Saxon 9.1 with FOP .95 (embedde - Added by Anonymous over 15 years ago

Legacy ID: #7182010 Legacy Poster: Michael Kay (mhkay)

>I was hoping to just put the Saxon jar files in the "lib" location of the application Relying on the search of the classpath is pretty unreliable in my experience, especially since the Xalan implementation is built in to the JDK so you can't remove it from the classpath. Searching the classpath is also very expensive. All the JARs except saxon9.jar are optional features that you don't need unless you use them. No known Saxon/FOP issues that I'm aware of.

RE: Newbie: using Saxon 9.1 with FOP .95 (embedde - Added by Anonymous over 15 years ago

Legacy ID: #7208858 Legacy Poster: Francis Parsons (fparsons)

Hello again - I have a stylesheet where I put this in to get the name of the vendor of the xslt processor: <xsl:value-of select="system-property('xsl:vendor')"/> I'm using a Websphere 5.1 application. I put in the "saxon9.jar" file in the designated "lib" directory. There is also Xalan 2.7 in there. Whether or not I use this line (in the code above): TransformerFactory factory = TransformerFactory.newInstance(); or this one: factory = new net.sf.saxon.TransformerFactoryImpl() according to the stylesheet the processor vendor is always "Saxon 9.1. from Saxonica" If I remove the Saxon9.jar and use "TransformerFactory factory = TransformerFactory.newInstance(); " the vendor reads "IBM". (I don't understand which JRE gets used and why it's not "Apache Software Foundation Xalan"). I would like to be able to have the option of using either processor (for testing). Is this possible with an embedded application? Could you explain why this problem exists? Thanks for any help with this! --- Francis

RE: Newbie: using Saxon 9.1 with FOP .95 (embedde - Added by Anonymous over 15 years ago

Legacy ID: #7209104 Legacy Poster: Michael Kay (mhkay)

I think I already said that relying on the classpath for which processor to load was unreliable. It's safer to specify the Java system property, and safer still to load the required TransformerFactory explicitly. Helping you to load different versions of Xalan is really quite outside the scope of this forum. I believe it's something to do with installing Xalan in the lib/endorsed directory, but I really can't advise on that. Setting the system property jaxp.debug="1" can help with debugging.

RE: Newbie: using Saxon 9.1 with FOP .95 (embedde - Added by Anonymous over 15 years ago

Legacy ID: #7210021 Legacy Poster: Francis Parsons (fparsons)

OK, so I would need to load the Xalan TransformerFactory explicitly - and I understand that you're here to answer questions about Saxon! Thanks for your help so far though! --- Francis

RE: Newbie: using Saxon 9.1 with FOP .95 (embedde - Added by Anonymous over 15 years ago

Legacy ID: #7244240 Legacy Poster: Francis Parsons (fparsons)

Michael - I did find that setting the jaxp property seems to work: String key = "javax.xml.transform.TransformerFactory"; //String value = "org.apache.xalan.xsltc.trax.TransformerFactoryImpl"; String value = "net.sf.saxon.TransformerFactoryImpl"; System.setProperty(key,value); -- Francis

    (1-9/9)

    Please register to reply