Appendix A. API Quick References

🛈︎
A word about type conversion

When interacting with JavaScript from XSLT, and vice versa, it is important to be aware of type conversion: XDM to JavaScript, and JavaScript to XDM.

The SaxonJS internal conversions are designed to do "what you'd expect", but there are times that this might not be straightforward.

We’re not going to try to explain all the conversions here, but the gory details are all in the documentation!

1 SaxonJS API

1.1 SaxonJS.atom()

SaxonJS.atom(value, type?)

Constructs an XDM atomic value.

value (Boolean, Number or String) JavaScript value to be converted.

type (String) Local name of a built-in atomic type in the “xs” namespace: e.g. “integer”, “decimal”, “dateTime”.

1.2 SaxonJS.getProcessorInfo()

SaxonJS.getProcessorInfo()

Returns an object containing standard information about the processor. The properties of the returned object include: version, vendor, vendorURL, productName, productVersion, isSchemaAware, supportsSerialization, supportsBackwardsCompatibility, supportsNamespaceAxis, supportsStreaming, supportsDynamicEvaluation, supportsHigherOrderFunctions, xPathVersion, and xsdVersion.

1.3 SaxonJS.getResource()

SaxonJS.getResource(options)

Retrieves a resource asynchronously, delivering a Promise which is fulfilled when the resource is available.

options is a JavaScript object with the following properties:

  • location (String or URL)

  • file (String)

  • text (String)

  • type (String: "text", "json", or "xml")

  • encoding (String)

  • text (String)

  • baseURI (String)

  • text (String)

  • headers (Object)

Exactly one of location, file, or text must be supplied.

1.4 SaxonJS.transform()

SaxonJS.transform(options, execution?)

Executes an XSLT transformation from a supplied SEF, as specified by the supplied options. Returns an object containing the transformation results (see below).

options (Object)

An object used to supply the transform options: the stylesheet location, principal input document, invocation options, additional resources, result delivery, and transformation behavior.

Stylesheet location
  • stylesheetLocation (String)

  • stylesheetFileName (String)

  • stylesheetText (String)

  • stylesheetInternal (Object)

  • stylesheetBaseURI (String)

Principal result document
  • sourceType (String: "xml" (default) or "json")

  • sourceLocation (String)

  • sourceFileName (String)

  • sourceNode (DOM Node)

  • sourceText (String)

  • sourceBaseURI (String)

Invocation options
  • stylesheetParams (ParameterMap)

  • initialTemplate (String)

  • templateParams (ParameterMap)

  • tunnelParams (ParameterMap)

  • initialFunction (String)

  • functionParams (Array)

  • initialMode (String)

  • initialSelection (XDM value)

Additional preloaded resources
  • documentPool (Object)

  • textResourcePool (Object)

Result delivery
  • destination (String: "replaceBody", "appendToBody", "prependToBody", "raw", "document", "application", "file", "stdout" or "serialized")

  • resultForm (String: "default", "array", "iterator", or "xdm")

  • deliverMessage (Function)

  • deliverResultDocument (Function)

  • masterDocument (DOM Node)

  • baseOutputURI (String)

Transformation behavior
  • collations (Object)

  • collectionFinder (Function)

  • logLevel (Number)

  • nonInteractive (Boolean)

execution (String: "sync" or "async")

Specifies whether the execution of the transform is synchronous or asynchonous.

The transformation results object also has properties:

  • principalResult (Object)

  • resultDocuments (Object)

  • stylesheetInternal (Object)

  • masterDocument (DOM Node)

1.5 SaxonJS.serialize()

SaxonJS.serialize(value, options?)

Produces a serialization of the supplied JavaScript value. The value is first converted to an XDM value (using the "weak" conversion rules defined in the documentation), and then serialized according to the rules of the W3C XDM Serialization Recommendation version 3.1.

value (Object)

options (Object) Serialization parameters e.g. {method:"xml", indent:true}

1.6 SaxonJS.setLogLevel()

SaxonJS.setLogLevel(level)

Used to set the logging level for warnings, processing messages, or full tracing.

level (Number) 0 switches off warnings; 1 is the default; 2 or higher adds some processing messages; and 10 provides full tracing.

1.7 SaxonJS.XPath.evaluate()

SaxonJS.XPath.evaluate(xpath, contextItem?, options?)

Evaluates an XPath 3.1 expression with JavaScript arguments and results. No compiled XSLT stylesheet (SEF) is required.

xpath (String)

XPath expression to be evaluated.

contextItem (Object)

Used to supply a context item for the expression. The supplied JavaScript object is converted to an XDM value according to the "strong" conversion rules (as defined in the documentation).

options (Object)

Used to supply values for the static and dynamic evaluation of the expression, and to indicate how the result should be delivered. In the absence of this argument default option values are used. The options available are:

  • params (Object)

  • staticBaseURI (String)

  • namespaceContext (Object)

  • xpathDefaultNamespace (String)

  • defaultDecimalFormat (Object)

  • namedDecimalFormats (Object)

  • resultForm (String: "default", "array", "iterator", or "xdm")

1.8 XError

Describes errors that occur.