2 ixsl: Quick Reference
In this section, we'll focus on SaxonJS in the browser, e.g. talking about the HTML page. When using SaxonJS on Node.js, there is no HTML page, but instead you can supply a “master document” when invoking the transformation, which acts in a similar way.
Examples of JavaScript objects that you may want to work with:
the window object
event objects
nodes in the HTML DOM
objects returned by extension functions
Note that nodes in the HTML DOM can be treated as both XDM nodes, and as JavaScript objects.
2.1 Extension functions
Accessing important objects: ixsl:event(), ixsl:page(), ixsl:source(), ixsl:window()
Accessing other information: ixsl:location(), ixsl:query-params(), ixsl:style()
Accessing properties of JavaScript objects: ixsl:contains(), ixsl:get()
Calling JavaScript code: ixsl:apply(), ixsl:call(), ixsl:eval() and "js" namespace shorthand for global JS functions
2.1.1 ixsl:apply
ixsl:apply($function as item(),
$arguments as array(*)) as item()*
Applies a JavaScript function.
$function
JavaScript function object
$arguments
Arguments to the function, supplied as an array
2.1.2 ixsl:call
ixsl:call($object as item(),
$method as xs:string,
$arguments as array(*)) as item()*
Calls a JavaScript function from a specified object.
$object
JavaScript object on which the function is defined
$method
Either a function name or a dot (character '.') separated
list of names
$arguments
Arguments to the function, supplied as an array
2.1.3 ixsl:contains
ixsl:contains($object as item(),
$property as xs:string) as xs:boolean
Test if a property is present on a JavaScript object.
$object
JavaScript object
$property
Either a property name or a dot
(character '.') separated list of names
2.1.4 ixsl:eval
ixsl:eval($script as xs:string) as item()*
Executes JavaScript code, supplied as a string.
$script
JavaScript code
2.1.5 ixsl:event
ixsl:event() as item()?
Returns the current Event object while processing a user input event (or the empty sequenceotherwise).
2.1.6 ixsl:get
ixsl:get($object as item(),
$property as xs:string) as item()*
Gets a property of a JavaScript object.
$object
JavaScript object
$property
Property name, or dot (character '.')
separated list of names
2.1.7 ixsl:location
ixsl:location() as xs:string
Returns the value of the href property of the Window.location object. Used to get the current location URL as a string.
2.1.8 ixsl:page
ixsl:page() as node()
Returns the document node of the HTML DOM document (or on Node.js, the document node supplied as the master document, if any).
2.1.9 ixsl:query-params
ixsl:query-params() as map(*)
Parses the query parameters of the HTML page URI, returning the values as an XPath map.
2.1.10 ixsl:source
ixsl:source() as node()?
Returns the global context item - the document node supplied as input to the transformation using a parameter such as sourceNode, sourceLocation, or sourceText, if such a source document was supplied, or the empty sequence otherwise.
2.1.11 ixsl:style
ixsl:style($node as item()?) as map(*)
Returns an XPath map containing the style properties of an HTML element node.
$node
HTML element node
2.1.12 ixsl:window
ixsl:window() as item()
Returns the Window object.
2.2 ixsl: extension instructions
“(AVT)” means the attribute is interpreted as an attribute value template, so it may contain string expressions within curly braces.
object?
means the attribute is optional.
Setting and removing attributes on elements in the HTML page (or master document): ixsl:set-attribute, ixsl:remove-attribute
Setting and removing properties of JavaScript objects: ixsl:set-property, ixsl:remove-property, ixsl:set-style
Asynchronous processing (time delays, document fetching, HTTP client): ixsl:schedule-action
2.2.1 ixsl:remove-attribute
<ixsl:remove-attribute name="{eqname}" object?="expr"/>
Removes the attribute with a given name from the current element node, or other specified element node, in the HTML page. A typical use for this is to enable a disabled HTML element by removing the disabled attribute (setting the value has no effect).
@name
The name of the attribute to be removed. (AVT)
@object?
The element the attribute belongs to - when no object
attribute is present, the current node is used.
2.2.2 ixsl:remove-property
<ixsl:remove-property name="{token}" object?="expr"/>
Removes a property from a JavaScript object (including DOM nodes).
@name
Property name, or dot (character '.')
separated list of names. (AVT)
@object?
The object the property belongs to - when
no object attribute is present, the Window object is used.
2.2.3 ixsl:schedule-action
<ixsl:schedule-action wait?="expr" document?="{uris}"
http-request?="expr">
<ixsl:call-template />
</ixsl:schedule-action>
Makes an asynchronous call to the template named in an
xsl:call-template
instruction that is the only permitted body
content of ixsl:schedule-action
, either after waiting a specified
time, or after fetching specified documents, or after getting a
response from a specified HTTP request. The instruction returns an
item containing any associated JavaScript XMLHttpRequest objects, or
an empty sequence otherwise.
@wait?
Used to specify the delay in milliseconds
before the call is invoked; or when used with attributes
document
or http-request
, specifies a
timeout in milliseconds for the associated HTTP requests.
@document?
Used to specify documents to be fetched
before the call is invoked. A space-separated list of document URIs
can be used to specify multiple files (text, JSON, and XML).
@http-request?
Used to specify an HTTP request to
be made before the call is invoked (with the HTTP response as the
context).
2.2.4 ixsl:set-attribute
<ixsl:set-attribute name="{eqname}"
select="expr"
object?="expr"/>
Sets an attribute with a given name and value on the current element node, or other specified element node, in the HTML page.
@name
The name of the attribute to be added. (AVT)
@select
The attribute value.
@object?
The element the attribute should be added
to - when no object attribute is present, the current node is
used.
2.2.5 ixsl:set-property
<ixsl:set-property name="{token}"
select="expr"
object?="expr"/>
Sets the value of a property for a JavaScript object (including DOM nodes). A nested property can be set using a dot-separated name.
@name
Property name, or dot (character '.')
separated list of names. (AVT)
@select
Provides the new property value.
@object?
The object the property belongs to - when
no object attribute is present, the Window object is used.
2.2.6 ixsl:set-style
<ixsl:set-style name="{token}"
select="expr"
object?="expr"/>
Sets a style property of an HTML element.
@name
Style property name in camel-case. (AVT)
@select
Provides the new style property value.
@object?
The HTML element the style property
belongs to - when no object attribute is present, the current node is
used.