I’m attempting to transform baseFile.xml using xslTransform.xsl.
The xslTransform.xsl file uses some information from dataFile.xml which it refereces
using document(). The dataFile.xml file has a DOCTYPE defined by dataFile.dtd.
I’ve been attempting to do this using JAXP. My code
looks something like this:
TransformerFactory tfactory = TransformerFactory.newInstance();
InputStream xslTransform = ClassLoader.getSystemResourceAsStream("xslTransform.xsl");
Transformer transformer = tfactory.newTransformer(new StreamSource(xslTransform));
InputStream baseFile = ClassLoader.getSystemResourceAsStream(“baseFile.xml”);
new StreamResult(new FileOutputStream(“result.txt)));
I can successfully register a custom URI resolver that returns
the “dataFile.xml” when it’s called out during the transform.
But, none of the objects above have a setEntityResolver method that I can use
to resolve the reference to “dataFile.dtd” that’s in “dataFile.xml”.
Somewhere inside the transform method, it obviously must
create an XMLReader and use it to parse that externally referenced file. But,
there doesn’t appear to be any way to get a reference to that XMLReader
or to get the transform method to set the reader’s EntityResolver for me.
Surely this is possible. What’s the trick?