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. However, this doesn't 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).
A custom Ant task for Saxon has therefore been developed. This 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
The task is available in saxon9-ant.jar
, under the class name net.sf.saxon.ant.AntTransform
.
In general it follows the pattern of the
existing xslt task, with the following extra
attributes:
Attribute |
Values |
Description |
allowExtensions |
true|false (default true) |
Specifies whether calls to user-written extension functions are permitted |
dtdValidation |
true|false (default false) |
Specifies whether input documents should be DTD-validated. Note that the DTD is read even if not used for validation |
expandDefaults |
true|false (default true) |
Specifies whether attribute and element fixed and default values should be expanded when validating using a DTD or schema |
initialMode |
mode name (in Clark notation if namespaced) |
Specifies that stylesheet execution is to start in a given mode |
initialTemplate |
template name (in Clark notation if namespaced) |
Specifies that the stylesheet is to be entered at a named template |
lineNumbering |
true|false (default false) |
Specifies whether line numbers should be maintained for source documents |
recoveryPolicy |
silent|recover|fatal (default recover) |
Indicates how "recoverable errors" are to be handled |
schemaAware |
true|false (default false) |
Specifies whether Saxon-SA is required |
schemaValidation |
strict|lax|skip (default skip) |
Specifies and how input documents should be schema-validated |
tracing |
true|false (default false) |
Specifies whether stylesheet execution should be traced (voluminous!) |
xmlversion |
1.0|1.1 (default 1.0) |
Specifies the XML version used for validating names etc. |
The processor
and classpath
attributes have no effect.
Example usage:
<target name="release-userdoc" description="Generate User Documentation">
<taskdef name="saxon-xslt"
classname="net.sf.saxon.ant.AntTransform"
classpath="c:\saxon\saxon9ee.jar;c:\saxon\licenses"/>
<saxon-xslt in="${userdoc.dir}/catalog.xml"
style="${userdoc.dir}/render-page2.xsl"
schemaaware="true"
schemavalidation="strict"
out="${release.dir}/resources/doc/dummy.html">
<param name="destination" expression="offline"/>
</saxon-xslt>
</target>
The above example was used to generate this documentation. With multiple output files, a single document is specified for the principal output (which may be a dummy), and all other output files are written in relative locations with respect to this.