Hello,
I am having a problem when we changed our class to pass xalan a SAXSource object instead of a StreamSource object.
When using a StreamSource everything worked properly as expected. But when we switched over to SAXSource, none of the templates in the stylesheet are being applied. The result is just the default template (copy text and apply templates to children) is applied. So we just see the text of the original xml document all concatenated together.
Has anyone else run into this?
Here are the fragments...
Using a StreamSource (from TransformerResourceSource's process method):
documentAsStream = getMethod.getResponseBodyAsStream(); source = new StreamSource(documentAsStream);
And using SAXSource (from TransformerResourceSource's process method):
documentAsStream = getMethod.getResponseBodyAsStream();
InputSource inputSource = new InputSource(documentAsStream);
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setValidating(false);
factory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
SAXParser parser = factory.newSAXParser();
XMLReader xmlReader = parser.getXMLReader();
source = new SAXSource(xmlReader, inputSource);
And to use either of these fragments:
InputStream xslDocumentAsStream = null;
GetMethod xslGetMethod = null;
InputStream xmlDocumentAsStream = null;
GetMethod xmlGetMethod = null;
// TransformerResourceSource using jakarta httpclient to fetch document
// for data or stylesheet and allows source to be obtained via the
// getSource method. After the source is finished being used (e.g.
// after the transformation has taken place), the cleanup method is called.
TransformerResourceSource xslResources = new TransformerResourceSource();
xslResources.setUri(xslUri);
xslResources.process();
TransformerResourceSource xmlResources = new TransformerResourceSource();
xmlResources.setUri(xmlUri);
xmlResources.process();
xslSource = xslResources.getSource();
xmlSource = xmlResources.getSource();
outputResult = new StreamResult(output);
// create the transformer and transform
tFactory = TransformerFactory.newInstance();
transformer = tFactory.newTransformer(xslSource);
transformer.transform(xmlSource, outputResult);
xslResources.cleanup();
xmlResources.cleanup();
Thank you, Matt