Re: [xsl] Relative URI "my-report.dtd"; can not be resolved without a document URI.

Subject: Re: [xsl] Relative URI "my-report.dtd"; can not be resolved without a document URI.
From: "J.Pietschmann" <j3322ptm@xxxxxxxx>
Date: Wed, 30 Apr 2003 21:24:41 +0200
Brad Clark wrote:
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.

The problem is that the InputSource for the XML parser doesn't have a ystem ID.

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.

This is no surprise: the problem odccurs as the XML parser reads from the string. The parser doesn't use the URI resolver, this mechanism is used by the XSLT processor.

String test =
...
try {
return new SAXSource(new InputSource(new FileReader(new
File(REPORT_INPUT_BASEDIR + href))));

Use something like this for the string try { InputSource is = new InputSource(new StringReader(test)); is.setSystemId(REPORT_INPUT_BASEDIR + href); return new SAXSource(is); ...

Exact handling of the system Id may vary a bit, maybe you'll
have to adjust it so that if the DTD files are in /foo/bar/*.dtd
you may have to set it to either /foo/bar, /foo/bar/ or
/foo/bar/dummy or perhaps /foo/bar/existing-file.xml.

Alternatively, and possibly more robust, is to use an entity
resolver.

J.Pietschmann


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread