You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-dev@xmlgraphics.apache.org by Art Welch <ar...@EASTPOINT.COM> on 2000/02/01 19:25:48 UTC

FW: Using Xalan as XSLT Engine ?

For what it is worth... I have been able to get Xalan SAX working by
subclassing the Driver class and overriding buildFOTree(). My code looks
like this:

import java.io.*;

// SAX
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;

// XALAN
import org.apache.xalan.xslt.XSLTProcessor;
import org.apache.xalan.xslt.XSLTInputSource;
import org.apache.xalan.xslt.StylesheetRoot;

// FOP
import org.apache.fop.fo.FOTreeBuilder;
import org.apache.fop.apps.FOPException;

public class PCLDriver extends org.apache.fop.apps.Driver
{
    public void buildFOTree(StylesheetRoot stylesheet, XSLTInputSource
source)throws FOPException
    {
		try
		{
		    stylesheet.process(source, new
org.apache.xalan.xslt.XSLTResultTarget(this.treeBuilder));
		}
		catch (SAXException e)
		{
		    if ( e.getException() instanceof FOPException )
				throw (FOPException) e.getException();
		    else
				throw new FOPException(e.getMessage());
		}
		catch (IOException e)
		{
		    throw new FOPException(e.getMessage());
		}
    }
...

This is invoked as follows:

XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
// Build the stylesheet
StylesheetRoot stylesheet = processor.processStylesheet(args[1]);
...
driver.buildFOTree(stylesheet, new XSLTInputSource(bis));


>-----Original Message-----
>From:	Art Welch 
>Sent:	Thursday, January 27, 2000 11:40 AM
>To:	'fop-dev@xml.apache.org'
>Subject:	RE: Using Xalan as XSLT Engine ?
>
>If you create your own CommandLine class it is easy to use Xalan to generate
>the DOM. I have not tried to do SAX yet.
>
>My code is as follows (you will need to change the renderer, my code uses my
>PCL renderer):
>
>    public static void main(String[] args)
>    {
>		String version = Version.getVersion();
>		System.err.println(version);
>			
>		if (args.length < 2) {
>		    System.err.println("usage: java PCLCommandLine formatting-object-file
>pcl-file\n\n       OR\n\n       "
>		    						+ "java PCLCommandLine xml-file xsl-stylesheet pcl-file\n\n"
>		    						+ "note: If the output file extension is 'pdf' then a PDF file
>will be produced,\n      otherwise a PCL file will be produced.");
>		    System.exit(1);
>		}
>			
>		Parser parser = createParser();
>			
>		if (parser == null) {
>		    System.err.println("ERROR: Unable to create SAX parser");
>		    System.exit(1);
>		}
>
>		Document fobdom = null;
>
>		if ( args.length == 3 )
>		{
>			try
>			{
>			    // Use the XSLTProcessorFactory to create a processor.  
>			    // Hopefully some sort of factory interface and XSLTProcessor 
>			    // interface will be standard someday.
>			    XSLTProcessor processor = XSLTProcessorFactory.getProcessor();
>			    
>				// Create the DOM for the Formatting Objects.
>				fobdom = new org.apache.xerces.dom.DocumentImpl();
>
>				System.out.println((new Date()).toString() + " processing XSL...");
>				// Process the stylesheet.
>				processor.process(new XSLTInputSource(args[0]),
>								new XSLTInputSource(args[1]),
>								new XSLTResultTarget(fobdom));
>				System.out.println((new Date()).toString() + " processed XSL.");
>			}
>			catch ( Exception e )
>			{
>				System.err.println("FATAL ERROR: Unable to process stylesheet.");
>				e.printStackTrace();
>				System.exit(1);
>			}
>		}
>		
>		try
>		{
>		    PCLDriver driver = new PCLDriver();
>			if ( args[args.length - 1].length() > 4 && args[args.length -
>1].substring(args[args.length - 1].length() - 4).equalsIgnoreCase(".pdf") )
>		    	driver.setRenderer("org.apache.fop.render.pdf.PDFRenderer", version);
>			else
>				driver.setRenderer(new PCLRenderer());
>		    driver.addElementMapping("org.apache.fop.fo.StandardElementMapping");
>		    driver.addElementMapping("org.apache.fop.svg.SVGElementMapping");
>		    //driver.setWriter(new PrintWriter(new FileWriter(args[args.length -
>1])));
>		    driver.setOutputStream(new FileOutputStream(args[args.length - 1]));
>			System.out.println((new Date()).toString() + " building formatting object
>tree...");
>			if ( args.length == 3 )
>			    driver.buildFOTree(fobdom);
>			else
>			    driver.buildFOTree(parser, fileInputSource(args[0]));
>			System.out.println((new Date()).toString() + " formatting...");
>		    driver.format();
>			System.out.println((new Date()).toString() + " rendering...");
>		    driver.render();
>			System.out.println((new Date()).toString() + " Done.");
>		}
>		catch (Exception e)
>		{
>		    System.err.println("FATAL ERROR: " + e.getMessage());
>		    System.exit(1);
>		}
>    }
>
>-----Original Message-----
>From:	Fotis Jannidis [SMTP:Fotis.Jannidis@lrz.uni-muenchen.de]
>Sent:	Thursday, January 27, 2000 6:06 AM
>To:	fop-dev@xml.apache.org
>Subject:	Re: Using Xalan as XSLT Engine ?
>
>> Hi 
>> 
>> Is it possible to use Xalan rather than XT as XSLT engine with FOP?
>> Like it's possible to use Xerces as XML Parser with :
>> Dorg.xml.sax.parser=org.apache.xerces.parsers.SAXParser
>
>AFAIK: No, XTCommandLine usage of XT is hardcoded. 
>Fotis