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

problem chaining stylesheets with java

Subject: problem chaining stylesheets with java
From: Paul Tremblay <phthenry@xxxxxxxxxxxxx>
Date: Wed, 18 Feb 2004 13:28:00 -0500
sax filter java
I am trying to write a java application to chain together xslt
stylesheets. My code below is taken out of Michael Kay's book. I almost
have gotten it to run except the very last part. 

What I need to do is chain serveral stylesheets together, and then run
the final transfromation through a SAX filter to change the encoding of
the file. (I need to change unicode to microsoft ascii: &#214; =>
/'u214/'d6)

The first two stylesheets transform the document. But the last SAX
filter has no affect. I know that the document is running through the
SAX filter because if I tell the SAX class to simply print out the name
of the element, it does. But the SAX class does not filter to my final
output.

Oddly enough, if I had an extra stylesheet *after* the SAX filter, then
the SAX filter does take affect.

I am probably overlooking something silly.

Thanks

Paul

*******************************************************

//run program which will have a pipe

import javax.xml.transform.*;
import javax.xml.transform.stream.*;
import javax.xml.transform.sax.*;
import org.xml.sax.XMLFilter;
import java.io.File;
import org.xml.sax.helpers.XMLFilterImpl;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;


class Pipeline{
    public static void main(String[] args) throws Exception{
        int len = args.length;
	if (len != 1){
	   System.err.println("Please provide one argument");
	   System.exit(1);
	}
	new Pipeline().run(args[0]);
    }
    public void run(String input) throws Exception{
	StreamSource source = new StreamSource(new File(input));
	File style = new File("/home/paul/paultemp/test.xsl");
	File style2 = new File("/home/paul/paultemp/test2.xsl");
	File style3 = new File("/home/paul/paultemp/test3.xsl");
	TransformerFactory factory = TransformerFactory.newInstance();
	if (!factory.getFeature(SAXTransformerFactory.FEATURE_XMLFILTER)){
	    System.err.println("SAX Filters are not supported");
        }
	else{
	   System.err.println("Okay, we're ready to go!");
	   SAXTransformerFactory saxFactory = (SAXTransformerFactory)factory;

           //first filter
	   XMLFilter filter = saxFactory.newXMLFilter(new StreamSource(style));
	   filter.setParent(new com.icl.saxon.aelfred.SAXDriver());
           

           //second filter
	   XMLFilter filter2 = saxFactory.newXMLFilter(new StreamSource(style2));
	   filter2.setParent(filter);

           //third filter
	   XMLFilter filter3 = new PostFilter();
	   filter3.setParent(filter2);

           //If I used a fourth filter and change the last two lines in this method to
           //"filter4", then the above SAX filter works!
           //fourth filter
	   //XMLFilter filter4 = saxFactory.newXMLFilter(new StreamSource(style3));
	   //filter4.setParent(filter3);

	   TransformerHandler serializer = saxFactory.newTransformerHandler();
	   serializer.setResult(new StreamResult (System.out));
	   Transformer trans = serializer.getTransformer();
	   filter3.setContentHandler(serializer);
	   filter3.parse(source.getSystemId());

	}

    }
}
//This is just temporary. I need to change all the character info
// to a funky encoding.
class PostFilter extends XMLFilterImpl{
    public void startElement(String uri, String localName, String qName, Attributes atts)
	    throws SAXException{
	    String newLocalName = localName.toUpperCase();
            //if the line below is uncommented, the new local name appears
	    //System.err.println(newLocalName);
	    super.startElement(uri, newLocalName, qName, atts);
	    }
}

-- 

************************
*Paul Tremblay         *
*phthenry@xxxxxxxxxxxxx*
************************

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


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.