I am trying to transform (with javax.xml.transform.Transformer) an XML structure that I create programmaticly (with org.xml.sax.ContentHandler), and this works perfectly I can write the XML out to a file and validate that it is created correctly. I then read an XSLT file in and attempt to transform the XML structure with it. The result does not have any of the XML data in it.
If I take the XML and add the xml-stylesheet instruction pointing to the XSLT file. I then open the XML file through a processor (I used Firefox) and the result is correct, it contains the transformation and the data from the XML. Which means that the XSLT is correct.
In the code sample below the doc.getSourceForDocument() is what builds the XML structure and [I]xslt[I] is the full path to the XSLT file used.
Thanks for any and all help.
posted 11 years ago
I have managed to get this to work, unfortunately it is not the most desirable way of doing things. I am writing the XML structure out to a temp file and then reading it back in and using that. This has some obvious performance issues, but at least it works.
Okay, now I think I see your problem. Your Source object contains an input stream. (You can't tell that by looking at your posted code.) The first transformation consumes all the data in that input stream and leaves its cursor positioned at end of file. The second transformation starts from there and then (of course) there's no more data to read.
So, using a File object as your source works because reading from it is repeatable. Perhaps the real fix should be to make doc.getSourceForDocument() return something that can be read repeatedly. Or perhaps the fix is as simple as this:
Again, it's not possible to say for sure without seeing what doc.getSourceForDocument() does.