Running XSLT from the Command Line
A command is available to apply a given stylesheet to a given source XML document. For simple transformations on the Java platform, use the command:
java net.sf.saxon.Transform -s:source -xsl:stylesheet -o:outputwhere source, stylesheet, and output are the source XML file, the XSLT stylesheet,B and the output file respectively.
For the .NET platform, the command is simply:
Transform -s:source -xsl:stylesheet -o:outputFor a schema-aware transformation, specify the option -sa
, or (on the
Java platform only) use the alternate entry point com.saxonica.Transform
.
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 the Home Edition):
java -jar dir/saxon9he.jar [options] [params]Note, however, that this does not work if you need to load user-written extension functions or other classes 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.
The options are as follows (in any order):
-a[:(on|off)] |
Use the xml-stylesheet processing instruction in the source document to identify the stylesheet to be used. The stylesheet argument must not be present on the command line. |
-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 . |
-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. |
-cr:classname |
Use the specified CollectionURIResolver to process collection URIs passed to the
|
-dtd:(on|off|recover) |
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 -expand:off suppresses this. (In the case of DTD-defined defaults, this might not work with all XML parsers. It does work with the Xerces parser (default for Java) and the Microsoft parser (default for .NET)) |
-explain[:filename] |
Display an execution plan for the stylesheet. This is a representation of the expression tree after rewriting by the optimizer. It compbines 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 a tree in XML format. |
-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 |
-it:template |
Selects the initial named template to be executed. If this is namespaced, it can be
written as |
-l[:(on|off)] |
If |
-m:classname |
Use the specified Receiver to process the output from xsl:message. The class must implement
the |
-now:yyyy-mm-ddThh:mm:ss+hh:mm |
Sets the value of |
-o:filename |
Send output to named file. In the absence of this option, the results go to standard output.
If the source argument identifies a directory, this option is mandatory and must also identify
a directory; on completion it will contain one output file for each file in the source directory.
If the stylesheet writes secondary output files using the |
-opt:0...10 |
Set optimization level. The value is an integer in the range 0 (no optimization) to 10 (full optimization); currently all values other than 0 result in full optimization but this is likely to change in future. The default is full optimization; this feature allows optimization to be suppressed in cases where reducing compile time is important, or where optimization gets in the way of debugging, or causes extension functions with side-effects to behave unpredictably. (Note however, that even with no optimization, lazy evaluation may still cause the evaluation order to be not as expected.) |
-or:classname |
Use the specified OutputURIResolver to process output URIs appearing in the |
-outval:(recover|fatal) |
Normally, if validation of result documents is requested, a validation error is fatal. Setting
the option |
-p[:(on|off)] |
Use the PTreeURIResolver. This option is available in Saxon-PE and Saxon-EE only. It cannot be used in conjunction
with the -r option, and it automatically switches on the -u and -sa options. The effect is twofold. Firstly, Saxon-specific
file extensions are recognized in URIs (including the URI of the source document on the command line). Currently
the only Saxon-specific file extension is |
-quit:(on|off) |
With the default setting, |
-r:classname |
Use the specified URIResolver to process all URIs. The URIResolver is a user-defined class, that extends the net.sf.saxon.URIResolver class, whose function is to take a URI supplied as a string, and return a SAX InputSource. It is invoked to process URIs used in the document() function, in the xsl:include and xsl:import elements, and (if -u is also specified) to process the URIs of the source file and stylesheet file provided on the command line. |
-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 |
-sa |
Invoke a schema-aware transformation. Requires Saxon-EE to be installed. This options is not needed if
either (a) another option implying schema-awareness is present (for example |
-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 writing, 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 net.sf.saxon.trace.TraceListener.
If the classname is omitted, a system-supplied trace listener is used.For performance profiling, set classname to |
-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. |
-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. -tree:tiny selects the "tiny tree" model (the default). -tree:linked selects the linked tree model. -tree:tinyc selects the "condensed tiny tree" model. See Choosing a 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 "http:" or "file:", in which case they are taken as URLs |
-val[:(strict|lax)] |
Requests schema-based validation of the source file and of any files read using the document()
or similar functions. Validation is available only with Saxon-EE, and this flag automatically switches on the
-sa option. Specify |
-versionmsg:(on|off) |
If versionmsg:off is specified, suppress version warnings.
This suppresses the warning message that is normally issued
(as required by the W3C specification) when running an XSLT 2.0 processor against a stylesheet
that specifies |
-warnings:(silent|recover|fatal) |
Indicates the policy for handling recoverable errors in the stylesheet: |
-x:classname |
Use specified SAX parser for source file and any files loaded using the document() function.
The parser must be the fully-qualified class name
of a Java class that implements the org.xml.sax.Parser or org.xml.sax.XMLReader interfaceOne use of this option is to select an HTML parser such as John Cowan's TagSoup rather than
an XML parser. In this case, the TagSoup JAR file must be on the classpath, and the class
name to use is |
-xi:(on|off) |
Apply XInclude processing to all input XML documents (including schema and stylesheet modules as well as source documents). This currently only works when documents are parsed using the Xerces parser, which is the default in JDK 1.5 and later. |
-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 "on" (the default) the schema processor attempts to load any schema documents referenced
in |
-xsl:filename |
Specifies the file containing the principal stylesheet module. Mandatory unless the -a option or -c option is used. The value "-" identifies the standard input stream. If the -u option is specified then the value must be a URI rather than a filename. |
-xsltversion:(2.0|3.0) |
Determines whether an XSLT 2.0 processor or XSLT 3.0 processor is to be used.
By default the value is taken from the version attribute of the |
-y:classname |
Use specified SAX parser for stylesheet file, including any loaded using |
--feature:value |
Set a feature defined in the |
-? |
Display command syntax |
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.
If the -a
option is used, the name of the stylesheet is
omitted. The source document must contain a <?xml-stylesheet?>
processing instruction
before the first element start tag; this processing instruction must have a pseudo-attribute href
that
identifies the relative or absolute URL of the stylsheet document, and a pseudo-attribute type whose
value is text/xml
, application/xml
, or text/xsl
. For example:
It is also possible to refer to a stylesheet embedded within the source document, provided it has an id attribute and the id attribute is declared in the DTD as being of type ID. For example:
<?xml-stylesheet type="text/xsl" href="#style1" ?> <!DOCTYPE BOOKLIST SYSTEM "books.dtd" <!ATTLIST xsl:transform id ID #IMPLIED> > <BOOKLIST> ... <xsl:transform id="style1" version="1.0" xmlns:xsl="..."> ... </xsl:transform> </BOOKLIST>