Command

The Command object is used exclusively by the Saxon object's run function. It's designed to be used as a JavaScript literal object and effectively wraps the Saxon-CE API with a set of properties so you can run an XSLT transform on an HTML page in a more declarative way.

If you need to include a namespace in an XSLT parameter name, use the Clark notation: {uri}local - for example {http://saxonica.com/units}mass-kg

In the properties listed below, only stylesheet (shown in italics) is mandatory, but either initialTemplate or source must also be set, to ensure that the stylesheet has an entry point.

Properties

Property

Type

Description

errorHandler

Function

The callback function for handling processing errors.

initialMode

String

The initial mode for the transform

initialTemplate

String

The initial template for the transform

logLevel

String

Sets the error and event logging threshold.

method

String

The transform method to use [Default: updateHTMLDocument]

parameters

Map:Name→Value

XSLT parameters are set from the matching values of properties of the parameters object.

source

String|Document

The XML document source for the transform

stylesheet

String|Document

Sets the stylesheet for the transform

success

Function

The success callback function - called after a transform.

Notes

An example of how the literal Command object can be used with the Saxon run method is shown below. This sample also shows how to use the onSaxonLoad function to ensure the Saxon-CE library loads fully before any JavaScript API calls are made on the library.

// Using Saxon.run method with the Command object to start an HTML page transform: var onSaxonLoad = function() { Saxon.run( { stylesheet: "display-geo.xsl", source: "geo-files.xml", initialMode: "pull", parameters: { mass-kg: 225, point: [128, 79], label: "Definitions" }, errorHandler: saxonHandler }); } // equivalent using the procedural JavaScript API: var onSaxonLoad = function() { var xml = Saxon.requestXML(geo-files.xml); var xsl = Saxon.requestXML("display-geo.xsl"); var proc = new XSLT20Processor(xsl); proc.setParameter(null, "mass-kg", 225); proc.setParameter(null, "point", [128, 79]); proc.setParameter(null, "label", "Definitions"); proc.setErrorHandler(saxonHandler); proc.updateHTMLDocument(xml, null); }