OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

docbook-apps message

[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]


Subject: Re: [docbook-apps] Embedding DocBook â PDF transformation in a Java web app


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

On 29 Jul 2023, at 22:37, Norm Tovey-Walsh <ndw@nwalsh.com> 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 <ndw@nwalsh.com> 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/



[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]