[
Lists Home |
Date Index |
Thread Index
]
- To: <xml-dev@lists.xml.org>
- Subject: Using templates with SaxTransformerFactory
- From: "Andrew Welch" <awelch@piper-group.com>
- Date: Tue, 23 Jul 2002 09:02:11 +0100
- Thread-index: AcIyFb0ODEdTLp2NSxy3voZB+fByOwACMsiQ
- Thread-topic: [xml-dev] URIs harmful
(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
|