XSLT from the command line
A command is available to apply a given stylesheet to a given source XML document.
For simple transformations using SaxonJ, use the command:
java net.sf.saxon.Transform -s:source -xsl:stylesheet -o:outputFor SaxonCS, the corresponding command is:
dotnet SaxonCS transform -s:source -xsl:stylesheet -o:outputHere source, stylesheet, and output are the source XML file, the XSLT stylesheet, and the output file respectively.
For a schema-aware transformation, specify the option -sa
. For more
details see Schema-aware
transformations.
For backwards compatibility with previous releases, the prefixes -s:
and
-xsl:
can be omitted provided that the source document and the stylesheet
are the last two options before any keyword=value parameters.
More generally, the arguments consist of a number of options prefixed with "-", then optionally (for backwards compatibility) the source filename and/or stylesheet filename, then a number of parameters provided as keyword=value pairs. The options must come first, then the file names if present, then the parameters.
For this to work, all the necessary Java components must be available on the classpath. See Installation for details of how to set up the classpath.
If you are are not using any additional Java libraries, you can use the simpler form of command (this example is for Saxon-HE 10.0):
java -jar dir/saxon-he-10.0.jar [options] [params]Note, however, that this does not work if you need to load user-written extension functions or other classes (such as the ICU localization library) from the classpath. It will therefore not work if your stylesheet uses extension functions or other plug-in components such as parsers or URI resolvers.
Command line options
The options are as follows (in any order). Square brackets indicate an optional value.
-a[:(on|off)] |
Use the |
-catalog:filenames |
filenames is either a file name or a list of file names separated by semicolons; the files are OASIS XML catalogs used to define how public identifiers and system identifiers (URIs) used in a source document, stylesheet, or schema are to be redirected, typically to resources available locally. For more details see Using XML catalogs. |
-config:filename |
Indicates that configuration information should be taken from the supplied configuration file. Any options supplied on the command line override options specified in the configuration file. |
-dtd:(on|off|recover) |
Setting |
-ea:(on|off) |
Setting |
-expand:(on|off) |
Normally, if validation using a DTD or schema is requested, any fixed or default
values defined in the DTD or schema will be expanded. Specifying
|
-explain[:filename] |
Display an execution plan and other diagnostic information for the stylesheet. This is a representation of the expression tree after rewriting by the optimizer. It combines the XSLT instructions and the XPath expressions into a single tree. If no file name is specified the output is sent to the standard error stream. The output is in XML format. |
-export:filename |
Export the compiled stylesheet, in a form suitable for subsequent execution. For more details, see Compiling a stylesheet. |
-ext:(on|off) |
If |
-im:modename |
Selects the initial mode for the transformation. If this is namespaced, it can be
written as |
-init:initializer |
The value is the name of a user-supplied class that implements the interface Initializer; this
initializer will be called during the initialization process, and may be used to
set any options required on the |
-it[:template-name] |
Selects the initial named template to be executed. If this is namespaced, it can
be written as |
-jit:on|off |
Determines whether just-in-time compilation of template rules is in force. The default
is |
-json:file-name |
Selects a JSON file to act as the primary input of the transformation. The file is
parsed (typically producing a map or array) following the rules of the This option cannot be combined with |
-l[:(on|off)] |
If |
-lib:filenames |
A list of filenames containing library packages. The filenames are separated by ";" on Windows systems, or ":" on Linux and Mac. Each filename must identify either (a) a top-level module in a source XSLT package, or (b) a SEF file containing an exported library package. There is no constraint on the order of the packages. |
-license:(on|off) |
Relevant only when SaxonJ-PE or SaxonJ-EE software is loaded. By default, Saxon will
look for a license and report a warning if none is found, which escalates to a fatal
error if licenseable features (such as schema-awareness) are used. If |
-m:classname |
From Saxon 11.1 this option has no effect. |
-nogo |
If set, the stylesheet is analysed for errors, and any requested
|
-now:yyyy-mm-ddThh:mm:ss+hh:mm |
Sets the value of |
-ns:(uri|##any|##html5) |
Defines the handling of unprefixed element names appearing as name tests in path expressions and match patterns in the stylesheet.
|
-o:filename |
Send output to named file. If the source ( In other cases, this option has two effects: it defines the file where the principal
output of the transformation will be written, and it defines the base URI used for resolving
the value of the In the absence of this option, (a) the principal output is written to the standard output stream, and (b) secondary output file locations are resolved relative to the current working directory. Output files are created if they do not already exist; any necessary directories will also be created. If a file does already exist, it is generally overwritten, though this will not necessarily happen if the transformation fails. |
-opt:[-]flags |
Allows individual optimizations to be enabled or disabled selectively. There is a set of single-letter flags identifying particular optimizations:
A value such as |
-or:classname |
Use the specified |
-outval:(recover|fatal) |
Normally, if validation of result documents is requested, a validation error is
fatal. Setting the option This option does not by itself cause result documents to be validated; that happens
only as a consequence of the Validating result documents can be very useful while debugging a stylesheet,
because it provides instant feedback when the output is incorrect. However, it can
sometimes be frustrating during development when you know that parts of the code have
not yet been written. The option |
-p[:(on|off)] |
Enable recognition of query parameters (such as |
-quit:(on|off) |
With the default setting, |
-r:classname |
Use the specified |
-relocate:(on|off) |
Used with The practical effect of this is that if |
-repeat:integer |
Performs the transformation N times, where N is the specified integer. This option is useful for performance measurement, since timings for the first transformation are often dominated by Java warm-up time. |
-s:filename |
Identifies the source file or directory. Mandatory unless the The filename can be given as
If the name
identifies a directory, all the files in the directory will be processed
individually. In this case the For backwards
compatibility the source filename can also be specified immediately before the
stylesheet filename, without the |
-sa |
Invoke a schema-aware transformation. Requires Saxon-EE to be installed. This
option is not needed if either (a) another option implying schema-awareness is
present (for example |
-scmin:filename |
Loads a precompiled schema component model from the given file. The file should be
generated in a previous run of This option is retained for compatibility. From Saxon 9.7, SCM files can also be
supplied in the |
-strip:(all|none|ignorable) |
Specifies what whitespace is to be stripped from source documents
(applies both to the principal source document and to any documents loaded for
example using the |
-t |
Display version and timing information to the standard error output. The output also traces the files that are read and written, and extension modules that are loaded. |
-T[:classname] |
Display stylesheet tracing information. This traces execution of each
instruction in the stylesheet, so the output can be quite voluminous. Also
switches line numbering on for the source document. If a classname is specified,
it is a user-defined class, which must implement TraceListener. If the classname is
omitted, a system-supplied trace listener is used. For performance profiling, set
classname to |
-target:(EE|PE|HE|JS) |
Relevant only when |
-TB:filename |
Monitors generation of hot-spot bytecode and produces an XML report on the given filename giving, for each expression that was a candidate for bytecode generation and that was actually executed, data about the number of times and speed of execution in the interpreter, the number of times and speed of execution in compiled form, and the cost of compilation. |
-threads:N |
Used only when the |
-TJ |
Switches on tracing of the binding of calls to external Java methods. This is useful when analyzing why Saxon fails to find a Java method to match an extension function call in the stylesheet, or why it chooses one method over another when several are available. |
-Tlevel:none|low|normal|high |
Controls the level of detail of the tracing produced by the
|
-Tout:filename |
Directs the output of tracing to a specified file (assuming that |
-TP:filename |
This is equivalent to setting
|
-traceout:filename |
Indicates that the output of the |
-tree:(linked|tiny|tinyc) |
Selects the implementation of the internal tree model: |
-u |
Indicates that the names of the source document and the stylesheet document are
URLs; otherwise they are taken as filenames, unless they start with
|
-val[:(strict|lax)] |
Requests schema-based validation of the source file and of any files read using
the |
-warnings:(silent|recover|fatal) |
No longer used. |
-x:classname |
Use the specified SAX parser for the source file and any files loaded using the
|
-xi:(on|off) |
Apply XInclude processing to all XML documents, with the exception of stylesheet modules.
This relies on XInclude support in the XML parser. The option affects documents read
using functions such as |
-xmlversion:(1.0|1.1) |
If |
-xsd:file1;file2;file3... |
Loads additional schema documents. The declarations in these schema documents are
available when validating source documents (or for use by the
|
-xsdversion:(1.0|1.1) |
If |
-xsiloc:(on|off) |
If set to |
-xsl:filename |
Specifies the file containing the principal stylesheet module. Mandatory unless
the The selected file can contain either XSLT source code, or a compiled version of
the stylesheet (a SEF file) as produced using the |
-y:classname |
Use the specified SAX parser for stylesheet files, including any loaded using
|
--feature:value |
Set a feature defined in the |
-? |
Display command syntax. Note: under some shell languages, this needs to be escaped as |
--? |
Display a list of features that are available using the Note: under some shell languages, this needs to be escaped as |
Command line parameters
A param takes the form name=value
, name being the name of the
parameter, and value the value of the parameter. These parameters are accessible
within the stylesheet as normal variables, using the $name
syntax, provided
they are declared using a top-level xsl:param
element. If there is no such
declaration, the supplied parameter value is silently ignored. If the
xsl:param
element has an as
attribute indicating the required
type, then the string value supplied on the command line is cast to this type: this may
result in an error, for example if an integer is required and the supplied value cannot be
converted to an integer. If the parameter is declared with the option
static="yes"
(new in XSLT 3.0) then the value is supplied as a static
parameter value.
A param preceded by a leading question mark (?
) is interpreted as an
XPath expression. For example, ?time=current-dateTime()
sets the value of the
stylesheet parameter $time
to the value of the current date and time, as an
instance of xs:dateTime
, while ?debug=false()
sets the value of
the parameter $debug
to the boolean value false
. If the parameter
has a required type (for example <xsl:param name="p" as="xs:date"/>
),
then the supplied value must be compatible with this type according to the standard rules
for converting variable values and function arguments. The static context for this XPath
expression includes only the standard namespaces conventionally bound to the prefixes
xs
, fn
, xsi
, and saxon
. The static
base URI (used when calling the doc()
function) is the current directory. The
dynamic context contains no context item, position, or size, and no variables.
A param preceded by a leading exclamation mark (!
) is interpreted as an
output parameter. For example, !indent=yes
requests indented output. This is
equivalent to specifying the attribute indent="yes"
on an
xsl:output
declaration in the stylesheet. An output parameter specified on
the command line overrides one specified within the stylesheet. For parameters
doctype-system
, doctype-public
, and
saxon:next-in-chain
, a zero-length value is treated as "absent", that is,
the effect is to cancel any value that was set within the stylesheet.
A param preceded by a leading plus sign (+
) is interpreted as a
filename or directory. The content of the file is parsed as XML, and the resulting document
node is passed to the stylesheet as the value of the parameter. If the parameter value is a
directory, then all the immediately contained files are parsed as XML, and the resulting
sequence of document nodes is passed as the value of the parameter. For example,
+lookup=lookup.xml
sets the value of the stylesheet parameter
lookup
to the document node at the root of the tree representing the parsed
contents of the file lookup.xml
.
Under most operating systems it is possible to supply a value containing spaces by
enclosing it in double quotes, for example name="John Smith"
. This is a
feature of the operating system shell, not something Saxon does, so it may not work the
same way under every operating system or command processor. (In the jEdit console plugin,
for example, it has to be written as "name=John Smith"
.)
If the parameter name is in a non-null namespace, the parameter can be given a value using
the syntax {uri}localname=value
. Here uri
is the namespace URI of
the parameter's name, and localname
is the local part of the name.
This applies also to output parameters. For example, you can set the indentation level to 4
by using the parameter !{http://saxon.sf.net/}indent-spaces=4
. In this case,
however, lexical QNames using the prefix saxon
are also recognized, for
example !saxon:indent-spaces=4
. See also Additional serialization parameters.