Saxon doesn't support OASIS's XML Catalogs natively. But adding this support yourself is quite easy. You need the XML Commons Resolver from Apache. Make sure the JAR resolver.jar you will find in the archive is in you classpath. Then you need to call Saxon with the following options:
java -cp <saxon and resolver jars> \ -Dxml.catalog.files=<the catalog files> \ -Dxml.catalog.verbosity=1 \ net.sf.saxon.Transform \ -r org.apache.xml.resolver.tools.CatalogResolver \ -x org.apache.xml.resolver.tools.ResolvingXMLReader \ -y org.apache.xml.resolver.tools.ResolvingXMLReader \ <other options>
Please note that you will not receive any warnings if the catalog xml-file is invalid or if the DTDs the catalog refers to is not found. This can make trouble shooting difficult. Make sure you start out with a simple test!
In the following example the jars are stored in lib/ and the DTDs and catalog.xml file are stored in dtds/ like this:
stylesheet.xsl input.html lib/saxon9.jar lib/resolver.jar dtds/catalog.xml dtds/xhtml1-strict.dtd dtds/xhtml-symbol.ent dtds/xhtml-special.ent dtds/xhtml-lat1.ent
Using the following command we can transform input.html using the stylesheet and without fetching the dtds for xhtml-strict from Internet every time.
java -cp lib/saxon9.jar:lib/resolver.jar \ -Dxml.catalog.files=dtds/catalog.xml \ net.sf.saxon.Transform \ -r:org.apache.xml.resolver.tools.CatalogResolver \ -x:org.apache.xml.resolver.tools.ResolvingXMLReader \ -y:org.apache.xml.resolver.tools.ResolvingXMLReader \ -xsl:stylesheet.xsl -s:input.html
The input file is a XHTML file with a doctype like this:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> <head> <title>Example</title> </head> <body> ... </body> </html>
The catalog.xml file looks like this:
<!-- This file points out DTDs stored locally so that they don't have to be fetched from Internet --> <catalog prefer="public" xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog"> <system systemId="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd" uri="xhtml1-strict.dtd"/> </catalog>
The xhtml1-strict.dtd files are stored along with catalog.xml in the dtds directory. Also required are the ent-files that the DTDs refer to:
An alternative to the excessively long command mentioned above is to use Florent Georges's shell script to launch Saxon, that supports catalogs through additional options (see the script page or this blog post):
saxon --catalogs=<the catalog files> <other options>
A well-annotated Windows batch script to invoke Saxon with a catalog has been posted to the saxon-help forum by Phil Pfeiffer. [See https://sourceforge.net/projects/saxon/forums/forum/94027/topic/3545851]