[Some of this exchange unintentionally fell off-list.]

On 29 Jul 2023, at 22:37, Norm Tovey-Walsh <[email protected]> wrote:

> So what’s happened here is that classpath:/xsl/juno-driver.xsl has
> succeeded and now it’s trying to import docbook.xsl. Unfortunately, the
> java.net class doesn’t like classpath:, so the attempt to resolve
> “docbook.xsl” agains the base URI fails.
> 
> That said, I’m a little surprised that the XML Resolver doesn’t do the
> right thing for you in this case. They’re not found in the catalog, I
> suppose.

I think this was my blunder. At one point I was doing this:

factory.setURIResolver(new StandardURIResolver());

Although that class claims to support classpath: URIs, it's not an 
org.xmlresolver class. Omitting that line gets me further. (What gets used by 
default, XMLCatalogResolver?)

> If you use the full, absolute URI for the base stylesheet and setup a
> catalog to map that to the classpath: URI, I think it’ll work.

> On 30 Jul 2023, at 15:50, Norm Tovey-Walsh <[email protected]> wrote:
> 
>> Sounds promising... could you give me a little more hand-holding here? What 
>> would the full,
>> absolute URI look like here, and how do I set up a catalog and provide that 
>> to the machinery?
> 
> Sure. If you look in, for example, the xslTNG jar file, you’ll find a
> catalog in xmlresolver/catalog.xml that does the mapping for xslTNG. If
> you check out the repo, you’ll find targets in build.gradle that
> construct it from sources. It’s a bit fussy because I’m mapping a couple
> off different flavors for some resources.
> 
> If you’re using the latest XML Resolver (which is what you’ll get with
> Saxon 11+), then constructing a corresponding catalog for the URIs of
> your stylesheets should “just work”. The resolver will look for
> xmlresolver/catalog.xml files in jars on the classpath.

After a lot of trial and error (quick aside: I cannot, for the life of me, get 
any SLF4J logging output from Saxon or org.xmlresolver classes), if I do this:

private Document transformDocument(Document document) throws 
TransformerException, FileNotFoundException {
        DOMResult result = new DOMResult();
        TransformerFactory factory = TransformerFactory.newInstance();
        InputStream is = 
XmlTest.class.getResourceAsStream("/xsl/juno-driver.xsl");
        Source source = new StreamSource(is, "file:/xsl/juno-driver.xsl");
        Transformer transformer = factory.newTransformer(source);
        transformer.transform(new DOMSource(document), result);
        return (Document) result.getNode();
}

with this catalog.xml:

<?xml version="1.0" encoding="utf-8"?>
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
   <uri name="file:/xsl/juno-driver.xsl"
         uri="classpath:/xsl/juno-driver.xsl" />
   <uri name="file:/xsl/header-footer.xsl"
         uri="classpath:/xsl/header-footer.xsl" />
   <uri name="file:/xsl/table.xsl"
         uri="classpath:/xsl/table.xsl" />
   <uri name="file:/xsl/titlepage.xsl"
         uri="classpath:/xsl/titlepage.xsl" />
   <uri name="file:/xsl/docbook-xsl-1.79.2/fo/docbook.xsl"
         uri="classpath:/xsl/docbook-xsl-1.79.2/fo/docbook.xsl" />
   <uri name="file:/xsl/docbook-xsl-1.79.2/VERSION.xsl"
         uri="classpath:/xsl/docbook-xsl-1.79.2/VERSION.xsl" />
   <uri name="file:/xsl/docbook-xsl-1.79.2/fo/param.xsl"
         uri="classpath:/xsl/docbook-xsl-1.79.2/fo/param.xsl" />
</catalog>

I get as far as the catalog goes. That is, at this point it fails with:

Error 
  XTSE0165: I/O error reported by XML parser processing
  file:/xsl/docbook-xsl-1.79.2/lib/lib.xsl: /xsl/docbook-xsl-1.79.2/lib/lib.xsl 
(No such
  file or directory)
javax.xml.transform.TransformerConfigurationException: 
net.sf.saxon.s9api.SaxonApiException: I/O error reported by XML parser 
processing file:/xsl/docbook-xsl-1.79.2/lib/lib.xsl

Which seems pretty reasonable, because that's the next included file in 
fo/docbook.xsl and it's not in the catalog.

While I suspect this will work eventually, it seems more than slightly bogus. 
The 'name' attributes in the catalog.xml don't seem to matter until I get down 
to the DocBook files, at which point it seems to be imperative that they're 
'file:' URIs. Why am I setting the system ID on that first StreamSource using a 
'file:' URI? Is this all working as expected, and I just need to finish the 
catalog?

(And if anyone can tell me how to turn on SLF4J logging output, I suspect that 
would be a big help!)


-- 
Paul Hoadley
https://logicsquad.net/
https://www.linkedin.com/company/logic-squad/

Reply via email to