Open amclark42 opened 1 year ago
Thanks to @joelsjlee, we discovered that Saxon HE requires that the xmlresolver
JAR be available in the Java environment, or the Ant transformation fails with an ambiguous
[xslt] Caught an error during transformation: java.lang.reflect.InvocationTargetException
While Ant provides two methods for setting the classpath for an <xslt>
task, neither actually pulls in the xmlresolver
JAR. Saxon's documentation says that these methods are "unreliable", stating "the safest approach is to ensure that the Jar files needed to run Saxon are present on the externally-specified classpath (the classpath at the point where Ant is invoked), rather than relying on the task-specific classpath." Getting access to the JAR therefore requires user intervention at a technical level, such as by placing the JAR in ~/.ant/lib
.
This Ant build file is intended for use by people who may not have a lot of confidence with the command line or Java's complex needs, and so I added a check for the Java class org.xmlresolver.Resolver
. If the class is available, transformation can occur. If not, the new checkXmlResolver
task describes how to run Ant with the -lib
option, e.g. ant -lib common/lib
. (On Windows machines, the forward slash will display as a backward slash.)
First steps to creating a static site generator using Apache Ant. The build file has several stub Ant tasks, but the only one that works is the
previewArticle
task, which is also the default. This task prompts for an article ID (e.g. "000612"), then runs the XSLT to create an HTML preview of that article. To test, runant -lib common/lib
orant -lib common/lib previewArticle
from the repository main directory, and fill in an article identifier when prompted. An alternative is to set thearticle.id
property when calling Ant, e.g.ant -lib common/lib -Darticle.id=000612
. The HTML will be saved todhq-journal/dhq-preview/ARTICLE-ID.html
.Changes:
common/lib
, as well as Saxon's dependencies and licensesdhq-preview
to the.gitignore
filecommon/xslt/generate_static_articles.xsl
, which will use the DHQ table of contents to fill out the static site HTML with transformed articleshead.xsl
:$assets-path
which points to the DHQ assets directory. This value is used for<link>
s and<script>
s within the HTML<head>
//titleStmt/title
to fill in the HTML<title>
template_article.xsl
:$vol
,$issue
and$id
, since they are already set (with default values) in the included XSLTdhq2html.xsl
$fpath
, which uses volume, issue, and ID values to figure out the article's filepath$vol_no_zeroes
fromdhq2html.xsl
when checking to make sure an article is in the TOCPossible issues:
The Ant task may not work on Windows machines due to the directory separator being a forward slashStill needs testing on Windows machines. However, the build file now uses thefile.separator
property for OS-agnostic filepathspreviewArticle
task does not fail on transformation error, this may not be helpful in the long run