Hi there, I have a problem understanding the behaviour of a Xalan transformation that works perfectly well with one SAX source but not with another (albeit both of them should output the same events as far as I can tell)
I have a piece of code like this (inspired by the Xalan exmaples):
//check Xalan Environment
new EnvironmentCheck().checkEnvironment(new PrintWriter(System.out));
//get a sax parser for the CSV file, implements XMLReader
XMLReader reader = XMLReaderFactory.createXMLReader();
//setup the transformation
TransformerFactory tFactory = TransformerFactory.newInstance();
SAXTransformerFactory saxTFactory = (SAXTransformerFactory) tFactory;
TransformerHandler tHandler = saxTFactory.newTransformerHandler(
new SAXSource(
new InputSource(
new InputStreamReader(
new
FileInputStream("transform.xslt"),"ISO-8859-1"))));
//register sax event consumer
reader.setContentHandler(tHandler);
//setup output file with explicit encoding
tHandler.setResult(new StreamResult(
new OutputStreamWriter(
new FileOutputStream("output2.xml"),"ISO-8859-1")));
//setup the input
InputSource input = new InputSource(
new InputStreamReader(
new FileInputStream("input.xml"),"ISO-8859-1"));
// do the work
reader.parse(input);
--end code
which works absolutely fine and transforms my input.xml exactly as I want
using my transform.xslt.
The output is exactly the same as when I run those to files through Xalans
commandline tools.
Now if I replace the XMLReader by a custom XMLReader (i.e. the one from
http://www.onjava.com/pub/a/onjava/excerpt/java_xslt_ch5/index.html?page=1
called CSVXMLReader ) and run the code with an empty tHandler (i.e. no
stylesheet defined) the output
matches my original input.xml file exactly (apart from linebreaks).
If I now use transform.xslt again in tHandler I get an unexpected and in my
eyes wrong result where
various tags that the stylesheet should create are missing.
So now I have no idea what else to try. I tried a second handler, played with
the encodings etc.
I don't quite understand why the sax events that CSVXMLReader emits are in
anyway different than the ones
XMLReader emits - especially since when handled by a none stylesheet handler
they create the expected output.
I'll be thankful for any pointers!
Joerg
pgpffdD9QkHVW.pgp
Description: signature
