Running Saxon XSLT Transformations from Ant
It is possible to run a Saxon transformation from Ant using the standard xslt task, by
using the trax
processor and with an appropriate classpath
that
forces Saxon to be selected. This can now be used to provide the ability to take advantage
of the full range of capabilities offered by XSLT 2.0 in general and Saxon in particular
(for example, schema aware processing and multiple output files).
The custom Ant task developed for earlier Saxon releases is not being further developed, although it remains available. It is no longer issued as an intrinsic part of the Saxon product, but can be downloaded as a separate package from SourceForge: see https://sourceforge.net/project/showfiles.php?group_id=29872. For information, see the documentation accompanying Saxon 9.2 or earlier releases.
Saxon-specific configuration options can be specified using the attribute
child of the factory
element. For example, the following switches on Saxon
tracing (the equivalent of the -T
option on the command line):
For a full list of feature names, see Configuration Features or the Javadoc
documentation of class net.sf.saxon.lib.FeatureKeys
.
With Saxon-PE and Saxon-EE it is possible to get detailed control of the configuration by specifying the name of a Saxon configuration file using this mechanism, for example:
<factory name="com.saxonica.config.EnterpriseTransformerFactory"> <attribute name="http://saxon.sf.net/feature/configuration-file" value="config-de.xml"/> </factory>In this case this must be the first attribute.
The initial template and initial mode for the transformation can be specified using the
attribute names http://saxon.sf.net/feature/initialTemplate
and
http://saxon.sf.net/feature/initialMode
respectively. The value is a QName
in Clark notation (that is {uri}local
).
Note that names in Clark notation may also be used for the qualified names of stylesheet parameters and serialization options.
Note that an Ant transformation always has an input file. If necessary, a dummy file can be specified.
There is a history of bugs in successive releases of Ant that mean not all these features
work in every Ant version. In particular, the classpath
attribute of the
xslt
task element has been unreliable: 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.