Unicorn ECMAScript Interpreter
Reference Manual
XSLT Extensions
Version 2.0 (Draft)
31 October 2024

Abstract

This document describes XSLT extensions supported by Unicorn ECMAScript Interpreter (UESI).

Status of this document

This document forms part of the Unicorn ECMAScript Interpreter (UESI) Reference Manual.

Comments on this document may be sent to [email protected]

Table of contents

Appendices


1 Introduction

This document describes XSLT extensions supported by Unicorn ECMAScript Interpreter (UESI).

2 Overview

XSLT extensions provide built-in ECMAScript objects that support XSLT transformations. XSLT extensions are built on the top of XML extensions and DOM extensions implemented by UESI.

Processor objects represent XSLT processors.

Stylesheet objects represent XSLT stylesheets.

Pattern objects are used to represent XSLT paterns and to implement the XSLT pattern matching facility.

3 Conventions

Concepts and notation of the ECMA-262 Standard (ECMAScript Language Specification) are used in this document.

This document relies also on the concepts introduced in "Unicorn ECMAScript Interpreter Reference Manual. XML Extensions" and "Unicorn ECMAScript Interpreter Reference Manual. DOM Extensions".

4 XSLT Objects

There are certain built-in XSLT extension objects available whenever UESI begins execution of a program. One, the XSLT object, is accessible as an initial property of the global object. Others are accessible as initial properties of the XSLT object.

All XSLT extension objects implement the semantics of native ECMAScript objects as specified in ECMA-262.

In every case, the length property of a built-in Function object described in this section has the attributes { DontEnum, DontDelete, ReadOnly } (and no others). Every other property described in this section has the attributes { DontEnum, DontDelete } (and no others) unless otherwise specified.

4.1 The XSLT Object

The XSLT object does not have a [[Construct]] property; it is not possible to use the XSLT object as a constructor with the new operator.

The XSLT object does not have a [[Call]] property; it is not possible to invoke the XSLT object as a function.

The value of the internal [[Prototype]] property of the XSLT object is the Object prototype. The value of the internal [[Class]] property of the XSLT object is "XSLT".

4.2 Processor Objects

Processor objects represent XSLT processors.

Every Processor object implements the interface of XML Stream and contains the XML Stream prototype in its prototype chain. Each Processor instance, therefore, can be treated as XML Stream and can be used in every context where XML Stream is required.

4.2.1 The Processor Constructor Called as a Function

Not supported in the current release of UESI. Reserved for the future.

4.2.1.1 XSLT.Processor(...)

Not supported in the current release of UESI. Reserved for the future.

4.2.2 The Processor Constructor

When XSLT.Processor is called as part of a new expression, it is a constructor: it initializes the newly created Processor instance.

4.2.2.1 new XSLT.Processor()

Properties sourceURI, sourceNode, sourceStream, stylesheetURI, stylesheetNode, stylesheetStream, stylesheet, resultURI, resultNode and resultHandler of the newly created Processor instance are set to null. The new Object object is created and assigned to the param property of the newly created Processor instance.

4.2.3 Properties of the Processor Constructor

The value of the internal [[Prototype]] property of the Processor constructor is the Function prototype object.

Besides the internal properties and the length property (whose value is 0), the Processor constructor has the following properties.

4.2.3.1 XSLT.Processor.prototype

The initial value of the XSLT.Processor.prototype is the Processor prototype object.

This property has the attributes { DontEnum, DontDelete, ReadOnly }.

4.2.4 Properties of the Processor Prototype Object

The Processor prototype object is itself a Processor object (its [[Class]] is "XSLT.Processor"). Properties sourceURI, sourceNode, sourceStream, stylesheetURI, stylesheetNode, stylesheetStream, stylesheet, resultURI, resultNode and resultHandler of the Processor prototype are initially set to null. The param property is initially set to an Object object which initially has no individual properties.

The value of the internal [[Prototype]] property of the Processor prototype object is the XML Stream prototype object (the initial value of XML.Stream.prototype).

4.2.4.1 XSLT.Processor.prototype.constructor

The initial value of XSLT.Processor.prototype.constructor is the built-in Processor constructor.

4.2.4.2 XSLT.Processor.prototype.reset()

This function sets properties sourceURI, sourceNode, sourceStream, stylesheetURI, stylesheetNode, stylesheetStream, stylesheet, resultURI, resultNode and resultHandler of this Processor instance to to null and deletes all properties of the object referenced by the param property.

4.2.5 Properties of the Processor Instances

The value of the internal [[Prototype]] property of the Processor instance is the Processor prototype object.

The value of the internal [[Class]] property of the Processor instance is "XSLT.Processor".

Processor instances inherit properties from their [[Prototype]] object, have all properties of XML Stream instances and also have the following properties.

4.2.5.1 sourceURI

This property contains a string value that specifies the URI for the source document to be processed, or null if unspecified.

4.2.5.2 sourceNode

This property references the DOM Node object (i.e., the object that contains DOM Node prototype in its prototype chain) that specifies root of the source document. This property may be null if the source node is unspecified. Setting this property will automatically set sourceStream property to null.

The DOM Node object assigned to sourceNode needs not to be a Document node. It may be also an Element node.

4.2.5.3 sourceStream

This property references the XML Stream object (i.e., the object that contains XML Stream prototype in its prototype chain) that specifies the content of the source document. This property may be null if the source stream is unspecified. Setting this property will automatically set sourceNode property to null.

4.2.5.4 stylesheetURI

This property contains a string value that specifies the URI for the XSLT stylesheet to be used for processing, or null if unspecified.

4.2.5.5 stylesheetNode

This property references the DOM Node object (i.e., the object that contains DOM Node prototype in its prototype chain) that specifies root of the DOM representation of XSLT stylesheet. This property may be null if the stylesheet node is unspecified. Setting this property will automatically set stylesheetStream and stylesheet and properties to null.

The DOM Node object assigned to stylesheetNode needs not to be a Document node. It may be also an Element node.

4.2.5.6 stylesheetStream

This property references the XML Stream object (i.e., the object that contains XML Stream prototype in its prototype chain) that specifies the content of the XSLT stylesheet. This property may be null if the stylesheet stream is unspecified. Setting this property will automatically set stylesheetNode and stylesheet and properties to null.

4.2.5.7 stylesheet

This property references the Stylesheet object (i.e., object that has [[Class]] property equal to "XSLT.Stylesheet"). This property may be null if the Stylesheet object is unspecified. Setting this property will automatically set stylesheetNode and stylesheetStream and properties to null.

4.2.5.8 resultURI

This property contains a string value that specifies URI of the result document, or null is unspecified.

4.2.5.9 resultNode

This property references the DOM Node object (i.e., the object that contains DOM Node prototype in its prototype chain) that specifies the parent for result document fragment. This property may be null if the result node is unspecified. Setting this property will automatically set resultHandler and contentHandler and properties to null.

4.2.5.10 resultHandler

This property references the XML ContentHandler object (i.e., the object that contains XML ContentHandler prototype in its prototype chain) that specifies the functions for processing of XSLT result stream. This property may be null if the result handler is unspecified. Setting this property will automatically set contentHandler property to the same value and resultNode property to null.

4.2.5.11 param

This property references the Object object (i.e., object with [[Class]] equal to "Object". All propeties assigned to this object are treated as parameters of XSLT stylesheet.

This property has the attributes { DontDelete, DontEnum, ReadOnly }.

4.2.5.12 XML.Stream.prototype.start Applied to Processor Instances

When the Stream prototype function XML.Stream.prototype.start is applied to the Processor instance, the following steps are performed.

If the sourceNode is the document node, let D be the corresponding document. If the sourceNode is the element node, let D be the document that has this element as its element node. Otherwise, if sourceNode is not null, generate a runtime error.

If the sourceStream is not null, let D be an XML document with the content provided by the corresponding stream.

If both sourceNode and sourceStream are null, let D be the XML document referenced by URI assigned to sourceURI.

If the stylesheetNode is the document, let S be an XSLT stylesheet represented by the corresponding document. If the stylesheetNode is the element node, let S be an XSLT stylesheet represented by the XML subtree having this element node as its root. Otherwise, if stylesheetNode is not null, generate a runtime error.

If the stylesheetStream is not null, let S be an XSLT stylesheet with the content provided by the corresponding stream.

If the stylesheet is not null, let S be an XSLT stylesheet associated with the corrsponding Stylesheet instance.

If all stylesheetNode, stylesheetStream and and stylesheet are null, let S be the XSLT stylesheet referenced by URI assigned to stylesheetURI.

Perform XSLT transformation, using D as the source document and S as the stylesheet. Prior to the transformation, enumerate properties of the object referenced via param. For each property P having the value V perform the following steps. If V is undefined or null, let X be the XPath empty string value. If V is ECMAScript boolean value, let X be the corresponding XPath boolean value. If V is ECMAScript number value, let X be the corresponding XPath number value. If V is ECMAScript string value, let X be the corresponding XPath string value. In all these cases pass the parameter with the name P and the value X to XSLT processor. Otherwise generate a runtime error.

If the resultNode is not null, append the result fragment generated by XSLT processor to the children list of the corresponding node.

If the resultHandler is not null, use the corresponding content handler to process the result stream generated by XSLT processor.

If both resultNode and resultHandler are null, create a result document with URI assigned to resultURI.

4.3 Stylesheet Objects

Stylesheet objects represent XSLT stylesheets.

4.3.1 The Stylesheet Constructor Called as a Function

Not supported in the current release of UESI. Reserved for the future.

4.3.1.1 XSLT.Stylesheet(...)

Not supported in the current release of UESI. Reserved for the future.

4.3.2 The Stylesheet Constructor

When XSLT.Stylesheet is called as part of a new expression, it is a constructor: it initializes the newly created Stylesheet instance.

4.3.2.1 new XSLT.Stylesheet(source)

If source is a DOM Node object (its prototype chain contains the DOM Node prototype), let S be an XSLT stylesheet represented by the subtree rooted at the corresponding DOM node. This node must be a document or an element.

If source is an XML Stream object (its prototype chain contains the XML Stream prototype), let S be an XSLT stylesheet represented by content of the corresponding XML stream.

Otherwise let U be a string value computed by ToString( source ), and let S be an XSLT stylesheet located using URI U.

Associate XSLT stylesheet S with the newly created Stylesheet instance.

4.3.3 Properties of the Stylesheet Constructor

The value of the internal [[Prototype]] property of the Stylesheet constructor is the Function prototype object.

Besides the internal properties and the length property (whose value is 1), the Stylesheet constructor has the following properties.

4.3.3.1 XSLT.Stylesheet.prototype

The initial value of the XSLT.Stylesheet.prototype is the Stylesheet prototype object.

This property has the attributes { DontEnum, DontDelete, ReadOnly }.

4.3.4 Properties of the Stylesheet Prototype Object

The Stylesheet prototype object is itself a Stylesheet object (its [[Class]] is "XSLT.Stylesheet"). It is associated with the identity transformation XSLT styesheet (i.e., the stylesheet that creates result fragment indetical to the source document).

The value of the internal [[Prototype]] property of the Stylesheet prototype object is the Object prototype.

4.3.4.1 XSLT.Stylesheet.prototype.constructor

The initial value of XSLT.Stylesheet.prototype.constructor is the built-in Stylesheet constructor.

4.3.5 Properties of the Stylesheet Instances

The value of the internal [[Prototype]] property of the Stylesheet instance is the Stylesheet prototype object.

The value of the internal [[Class]] property of the Stylesheet instance is "XSLT.Stylesheet".

Stylesheet instances inherit properties from their [[Prototype]] object.

4.4 Pattern Objects

Pattern objects are used to represent XSLT paterns and to implement the XSLT pattern matching facility.

4.4.1 The Pattern Constructor Called as a Function

Not supported in the current release of UESI. Reserved for the future.

4.4.1.1 XSLT.Pattern(...)

Not supported in the current release of UESI. Reserved for the future.

4.4.2 The Pattern Constructor

When XSLT.Pattern is called as part of a new expression, it is a constructor: it initializes the newly created Pattern instance.

4.4.2.1 new XSLT.Pattern(source)

Let S be a string value computed by ToString( source ). If S is a valid XSLT pattern, assign it to the newly created Pattern instance. (For performance reasons, UESI compiles XSLT patterns into internal code every time the new Pattern instance is created). Otherwise, generate the runtime error.

4.4.3 Properties of the Pattern Constructor

The value of the internal [[Prototype]] property of the Pattern constructor is the Function prototype object.

Besides the internal properties and the length property (whose value is 1), the Pattern constructor has the following properties.

4.4.3.1 XSLT.Pattern.prototype

The initial value of the XSLT.Pattern.prototype is the Pattern prototype object.

This property has the attributes { DontEnum, DontDelete, ReadOnly }.

4.4.4 Properties of the Pattern Prototype Object

The Pattern prototype object is itself a Pattern object (its [[Class]] is "XSLT.Pattern"). The XSLT pattern "node()" (one that matches every node) is associated with the Pattern prototype.

The value of the internal [[Prototype]] property of the Pattern prototype object is the Object prototype.

4.4.4.1 XSLT.Pattern.prototype.constructor

The initial value of XSLT.Pattern.prototype.constructor is the built-in Pattern constructor.

4.4.4.2 XSLT.Pattern.prototype.match(node)

The node argument must be a DOM Node object (its prototype chain must contain the DOM Node prototype); otherwise a runtime error is generated. The function matches the node specified by node against the XSLT pattern associated with this Pattern instance. Returns true if the node matches and false otherwise.

During the matching, the following assumptions are made about the XPath expression contexts.

The variable bindings are represented by the empty set. The function library is XPath core function library (no XSLT extensions). Namespace declarations in scope on the node specified by node form the set of namespace declarations.

4.4.4.3 XSLT.Pattern.toString()

This function returns the string that contains a valid XSLT pattern equivalent to the XSLT pattern associated with this Pattern instance.

4.4.5 Properties of the Pattern Instances

The value of the internal [[Prototype]] property of the Pattern instance is the Pattern prototype object.

The value of the internal [[Class]] property of the Pattern instance is "XSLT.Pattern".

Pattern instances inherit properties from their [[Prototype]] object, and also have the following properties.

4.4.5.1 source

This property is a string value that contains a valid XSLT pattern equivalent to the XSLT pattern associated with this Pattern instance.

This property has the attributes { DontDelete, DontEnum, ReadOnly }.


Appendices

A References

[ECMA-262] ECMA. Standard ECMA-262 2nd Edition - August 1998. ECMAScript Language Specification. See http://www.ecma.ch
[XML] World Wide Web Consortium. Extensible Markup Language (XML) 1.0. W3C Recommendation 10-February-1998 (REC-xml-19980210). See http://www.w3.org/TR/REC-xml
[DOM] World Wide Web Consortium. Document Object Model (DOM) Level 1 Specification Version 1.0. W3C Recommendation 1 October, 1998 (REC-DOM-Level-1-19981001). See http://www.w3.org/TR/REC-DOM-Level-1
[XPath] World Wide Web Consortium. XML Path Language (XPath) Version 1.0. W3C Recommendation 16 November 2024 (REC-xpath-19991116). See http://www.w3.org/TR/1999/REC-xpath-19991116
[XSLT] World Wide Web Consortium. XSL Transformations (XSLT) Version 1.0. W3C Recommendation 16 November 2024 (REC-xslt-19991116). See http://www.w3.org/TR/1999/REC-xslt-19991116
[SAX2] Megginson Technologies. SAX 2.0: The Simple API for XML. See http://www.megginson.com/SAX/index.html
[UESI-XML] Unicorn Enterprises SA. Unicorn ECMAScript Interpreter Reference Manual. XML Extensions. Version 2.0. 31 October 2000. See https://www.unicorn-enterprises.com/esxxml.htm
[UESI-DOM] Unicorn Enterprises SA. Unicorn ECMAScript Interpreter Reference Manual. DOM Extensions. Version 2.0. 31 October 2000. See https://www.unicorn-enterprises.com/esxdom.htm

B Examples

Example 1.

The following example demonstrates 10 ways to perform XSLT transformation.

  var baseURI = "file://localhost/d/demo/uesi/";
  var sourceURI = baseURI + "demo01.xml";
  var stylesheetURI = baseURI + "demo01.xsl";
  demo01a();
  demo01b();
  demo01c();
  demo01d();
  demo01e();
  demo01f();
  demo01g();
  demo01h();
  demo01i();
  demo01j();
//
//    URI -> XSLT -> URI
//
  function demo01a() {
      var p = new XSLT.Processor();
      p.sourceURI = sourceURI;
      p.stylesheetURI = stylesheetURI;
      p.resultURI = baseURI + "demo01a.out";
      p.start();
      }
//
//    SAX -> XSLT -> URI
//
  function demo01b() {
      var p = new XSLT.Processor();
      var i = new XML.InputSource(sourceURI);
      var r = new XML.Reader();
      r.inputSource = i;
      p.sourceStream = r;
      p.stylesheetURI = stylesheetURI;
      p.resultURI = baseURI + "demo01b.out";
      p.start();
      }
//
//    DOM -> XSLT -> URI
//
  function demo01c() {
      var p = new XSLT.Processor();
      var xi = new XML.InputSource(sourceURI);
      var xr = new XML.Reader();
      var d = new DOM.Document();
      var dw = new DOM.Writer(d);
      xr.inputSource = xi;
      xr.contentHandler = dw;
      xr.start();
      var dr = new DOM.Reader(d);
      p.sourceStream = dr;
      p.stylesheetURI = stylesheetURI;
      p.resultURI = baseURI + "demo01c.out";
      p.start();
      }
//
//    URI -> XSLT -> URI, stylesheet from SAX
//
  function demo01d() {
      var p = new XSLT.Processor();
      var i = new XML.InputSource(stylesheetURI);
      var r = new XML.Reader();
      r.inputSource = i;
      p.sourceURI = sourceURI;
      p.stylesheetStream = r;
      p.resultURI = baseURI + "demo01d.out";
      p.start();
      }
//
//    URI -> XSLT -> URI, stylesheet from DOM
//
  function demo01e() {
      var p = new XSLT.Processor();
      var xi = new XML.InputSource(stylesheetURI);
      var xr = new XML.Reader();
      var d = new DOM.Document();
      var dw = new DOM.Writer(d);
      xr.inputSource = xi;
      xr.contentHandler = dw;
      xr.start();
      p.sourceURI = sourceURI;
      p.stylesheetNode = d;
      p.resultURI = baseURI + "demo01e.out";
      p.start();
      }
//
//    URI -> XSLT -> URI, precompiled stylesheet (from URI)
//
  function demo01f() {
      var p = new XSLT.Processor();
      var s = new XSLT.Stylesheet(stylesheetURI);
      p.sourceURI = sourceURI;
      p.stylesheet = s;
      p.resultURI = baseURI + "demo01f.out";
      p.start();
      }
//
//    URI -> XSLT -> URI, precompiled stylesheet (from SAX)
//
  function demo01g() {
      var p = new XSLT.Processor();
      var i = new XML.InputSource(stylesheetURI);
      var r = new XML.Reader();
      r.inputSource = i;
      var s = new XSLT.Stylesheet(r);
      p.sourceURI = sourceURI;
      p.stylesheet = s;
      p.resultURI = baseURI + "demo01g.out";
      p.start();
      }
//
//    URI -> XSLT -> URI, precompiled stylesheet (from DOM)
//
  function demo01h() {
      var p = new XSLT.Processor();
      var xi = new XML.InputSource(stylesheetURI);
      var xr = new XML.Reader();
      var d = new DOM.Document();
      var dw = new DOM.Writer(d);
      xr.inputSource = xi;
      xr.contentHandler = dw;
      xr.start();
      var s = new XSLT.Stylesheet(d);
      p.sourceURI = sourceURI;
      p.stylesheet = s;
      p.resultURI = baseURI + "demo01h.out";
      p.start();
      }
//
//    URI -> XSLT -> SAX
//
  function demo01i() {
      var p = new XSLT.Processor();
      var w = new XML.Writer();
      w.URI = baseURI + "demo01i.out";
      w.method = "xml";
      w.indent = true;
      w.encoding = "UTF-8";
      p.sourceURI = sourceURI;
      p.stylesheetURI = stylesheetURI;
      p.resultHandler = w;
      p.start();
      }
//
//    URI -> XSLT -> DOM
//
  function demo01j() {
      var p = new XSLT.Processor();
      var d = new DOM.Document();
      p.sourceURI = sourceURI;
      p.stylesheetURI = stylesheetURI;
      p.resultNode = d;
      p.start();
      var dr = new DOM.Reader(d);
      var xw = new XML.Writer();
      xw.URI = baseURI + "demo01j.out";
      xw.method = "xml";
      xw.indent = true;
      xw.encoding = "UTF-8";
      dr.contentHandler = xw;
      dr.start();
      }

Example 2.

The following example demonstrates chaining two XSLT transformations in a pipeline.

  var baseURI = "file://localhost/d/uxsl/bin/uxp/samples/";
  var sourceURI = baseURI + "uxpxsl02.xml";
  var stylesheetURIa = baseURI + "uxpxsl02a.xsl";
  var stylesheetURIb = baseURI + "uxpxsl02b.xsl";
  var resultURI = baseURI + "uxpxsl02.htm";
  var p1 = new XSLT.Processor();
  var p2 = new XSLT.Processor();
  p1.sourceURI = sourceURI;
  p1.stylesheetURI = stylesheetURIa;
  p2.sourceStream = p1;
  p2.stylesheetURI = stylesheetURIb;
  p2.resultURI = resultURI;
  p2.start();