Script Element
Using a Script Element is the the most direct way of executing an XSLT transform from
Saxon-CE. You need two script
elements, one for the Saxon-CE code, and
one for the XSLT stylesheet:
The first script
element is a reference to the Saxon-CE code, located by
means of a relative URI in the normal way. The module
Saxonce.nocache.js
is a small stub module located within the
Saxonce directory, this in turn brings in one of a number of larger modules
containing the compiled XSLT engine, in slightly different forms depending on which
browser is in use.
Note: The relative URI to the Saxon-CE code may reference either the debug or production directories that are shipped with Saxon-CE, depending on the requirement. See Installing the Software for details.
The second script
element typically contains references to the source
document and stylesheet. Again these are relative URIs.
The attributes recognized on this element are:
Attribute |
Meaning |
type |
Should always be |
language |
Should always be |
src |
Mandatory. Relative URI of the XSLT stylesheet |
data-source |
Optional. Relative URI of the initial source document. If absent, the
attribute |
data-initial-template |
Name of the named template in the stylesheet at which execution is to
commence. If this is namespace-qualified, use Clark notation
|
data-initial-mode |
Name of the mode in the stylesheet at which execution is to commence. If
this is namespace-qualified, use Clark notation
|
Assuming that data-source
is supplied, execution proceeds as follows.
When the page is loaded, the Saxon stub will be executed, the source document will
be fetched, the stylesheet will be compiled, and the stylesheet will be invoked with
the source document as its principal input (initial context node). So the
<xsl:template match="/"> template will be invoked in the usual way.
When using XSLT 1.0 in the browser, it is common to generate a complete HTML page as
output from the transformation. With XSLT 2.0, a more effective technique is to
write multiple fragments of HTML, using them to populate named portions of the HTML
page. So the initial HTML page will generally contain a skeletal structure of
elements such as div
element, each with an id
attribute,
waiting to be populated by the stylesheet.