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

Using templates with SaxTransformerFactory

  • To: <xml-dev@l...>
  • Subject: Using templates with SaxTransformerFactory
  • From: "Andrew Welch" <awelch@p...>
  • Date: Tue, 23 Jul 2002 09:02:11 +0100
  • Thread-index: AcIyFb0ODEdTLp2NSxy3voZB+fByOwACMsiQ
  • Thread-topic: URIs harmful

saxtransformerfactory
(I posted this yesterday on xsl-list but I think xml-dev is [hopefully]
more appropriate)

I am trying to use templates with XMLFilter()

I have a normal (non-templates) transform working with XMLFilter(), but
the only example Ive seen of using templates with SAXTransformerFactory
uses XMLReader().

As far as I can tell, I can only setParent() on XMLFilter()'s not on
XMLReaders so is it possible to use templates with
SAXTransformerFactory?

Here is my current working non-templates code:

SAXTransformerFactory saxFactory = (SAXTransformerFactory)factory;
ajwFilter xmlFilter = new ajwFilter();
xmlFilter.setParent(new com.icl.saxon.aelfred.SAXDriver());
XMLFilter styleSheet = saxFactory.newXMLFilter(new StreamSource(style));
styleSheet.setParent(xmlFilter);
TransformerHandler serializer = saxFactory.newTransformerHandler();
serializer.setResult(new StreamResult(System.out));
styleSheet.setContentHandler(serializer);
styleSheet.parse(source.getSystemId());

The following is basically what I've gleaned from the example, but it
doesn't
work because you can only chain xmlFilters and not xmlReaders - is it
possible to modify this code so it will work?:

SAXTransformerFactory saxFactory = (SAXTransformerFactory)factory;
TemplatesHandler templatesHandler =  saxFactory.newTemplatesHandler();
ajwFilter xmlFilter = new ajwFilter();
org.xml.sax.XMLReader styleSheet2 = 
  org.xml.sax.helpers.XMLReaderFactory.createXMLReader();
styleSheet2.setContentHandler(templatesHandler);
styleSheet2.parse("C:\\ajw\\test.xsl");
xmlFilter.setParent(new com.icl.saxon.aelfred.SAXDriver());
templates = templatesHandler.getTemplates();            
styleSheet2.setParent(xmlFilter);
//**fails here**
TransformerHandler serializer =
saxFactory.newTransformerHandler(templates);
serializer.setResult(new StreamResult(System.out));
styleSheet2.setContentHandler(serializer);
styleSheet2.parse(source.getSystemId());

Any advice on what is needed would be great, be gentle as Im a newbie :)

Cheers
andrew

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.373 / Virus Database: 208 - Release Date: 01/07/2002
 

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
 

Stylus Studio has published XML-DEV in RSS and ATOM formats, enabling users to easily subcribe to the list from their preferred news reader application.


Stylus Studio Sponsored Links are added links designed to provide related and additional information to the visitors of this website. they were not included by the author in the initial post. To view the content without the Sponsor Links please click here.

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.