[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Relative URI "my-report.dtd"; can not be resolved with
I'm using xsl/fop to generate dynamic pdf's from xml. The xml has an associated dtd which defines a number of entities. When the xml is not dynamic but is loaded from a file, which resides in the same directory as the dtd, the pdf gets generated fine. When the xml comes from a dynamic string, the dtd specified in the DOCTYPE isn't found. I know the reason is because the transformer doesn't have a base directory to use for the relative uri. I defined a URIResolver and called setURIResolver but it never seems to call the resolve callback. What do I need to do so that the Transformer finds my dtd. Attached is a snippet of code where the problem is occuring. Any help would be greatly appreciated. Thanks in Advance, Ralph // Code Snippet try { FileOutputStream out = new FileOutputStream(REPORT_OUTPUT_BASEDIR + "test.pdf"); Driver driver = new Driver(); //driver.setLogger(log); driver.setRenderer(Driver.RENDER_PDF); driver.setOutputStream(out); Configuration.put("strokeSVGText", "false"); Transformer transformer = TransformerFactory.newInstance().newTransformer( new StreamSource(new File(REPORT_INPUT_BASEDIR + "report-pdf-servlet.xsl"))); transformer.setURIResolver(new MyResolver()); String test = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>\n" + "<!DOCTYPE my-report SYSTEM \"my-report.dtd\" >\n" + "<my-report>\n" + "&cover1;\n" + "&introduction;\n" + "&body;\n" + "</my-report>\n"; transformer.transform(new StreamSource(new StringReader(test)), new SAXResult(driver.getContentHandler())); } catch (Exception e) { e.printStackTrace(); } public class MyResolver implements javax.xml.transform.URIResolver { public javax.xml.transform.Source resolve(String href, String base) throws javax.xml.transform.TransformerException { try { return new SAXSource(new InputSource(new FileReader(new File(REPORT_INPUT_BASEDIR + href)))); } catch (Exception e) { e.printStackTrace(); return null; } } } XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|