script

The script statement allows the provision of including extension functions within a specified namespace. See here for a complete guide to the definition and use.

Syntax
<script> ::= “script” “prefix” <quote> <namespace prefix> <quote> "language" <quote> <script language definition> <quote> ( "archive" <quote> <uri list> >quote> )? ( ( "src" <quote> <script uri> >quote> ) | ( <quote> <script text> >quote> ) )
Options
prefix The namespace prefix within which the script functions operate.
language The script language identifier.
archive An (optional) list of archives to be loaded before executing the extension function.
src An (optional) reference to a script to be loaded instead of the script text script language identifier

When the src option is not present the script to be used is presented in quotes after the options are defined. Either the src option is present or the actual script definition, but not both or neither.

Elements

None.

Examples

Using an example based on one from the W3C spec.

// Produced on 21/06/2024 16:33:35 // Uncompiler Version 1.0.1 stylesheet { version "1.1" xmlns "date" "http://www.example.com/2000/XSLT/library/date" parameter upperCust "true()" script prefix "date" language "ecmascript" src "DateRoutines.js" script prefix "util" language "ecmascript" " function upper(n) { return n.toUpperCase(); } function lower(n) { return n.toLowerCase(); } function iff(arg1, arg2, arg3) { if (arg1) { return arg2; } else { return arg3; } }" match using "/" { element "CustomerId" { value "util:iff($upperCust, util:upper(/order/custid), util:lower(/order/custid))" } element "OrderDate" { value "date:format(/order/date, 'MM/DD/YY')" } } }

will compile to

<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:date="http://www.example.com/2000/XSLT/library/date"> <xsl:param name="upperCust" select="true()"/> <xsl:script implements-prefix="date" language="ecmascript" src="DateRoutines.js"/> <xsl:script implements-prefix="util" language="ecmascript"> function upper(n) { return n.toUpperCase(); } function lower(n) { return n.toLowerCase(); } function iff(arg1, arg2, arg3) { if (arg1) { return arg2; } else { return arg3; } }</xsl:script> <xsl:template match="/"> <xsl:element name="CustomerId"> <xsl:value-of select="util:iff($upperCust, util:upper(/order/custid), util:lower(/order/custid))"/> </xsl:element> <xsl:element name="OrderDate"> <xsl:value-of select="date:format(/order/date, 'MM/DD/YY')"/> </xsl:element> </xsl:template> </xsl:stylesheet>
Errors

Forgetting the correct version.

stylesheet { version "1.0" xmlns "paloose" "http://www.paloose.org/schemas/Paloose/1.0" script prefix "paloose" language "javascript" src "DateRoutines.js" }

gives the error

**** (143) Illegal keyword "script" for version "1.0" in line 6 Update version number or remove keyword.

Misspelling the prefix or leaving out the XML nanespace.

stylesheet { version "1.1" xmlns "paloose" "http://www.paloose.org/schemas/Paloose/1.0" script prefix "palose" language "javascript" src "DateRoutines.js" }
stylesheet { version "1.1" script prefix "paloose" language "javascript" src "DateRoutines.js" }

Both give the error (excepting the line number is different).

**** (147) Namespace prefix "palose" not declared in script declaration in line 6 Insert namespace pair declaration for "palose"

Having a src and script source present.

stylesheet { version "1.1" xmlns "paloose" "http://www.paloose.org/schemas/Paloose/1.0" script prefix "paloose" language "javascript" src "DateRoutines.js" "function upper(n) { return n.toUpperCase(); }" }

gives the error

**** (145) Script statement cannot have both src or script declared in line 6 Remove one of the expressions
Copyright 2024 Hugh Field-Richards. All Rights Reserved.