Defines global variables and functions for script extensions.
Only valid with a stylsheet specifying the xsl namespace, http://www.w3c.org/TR/WD-xsl. Stylesheets using the XSLT namespace, http://www.w3c.org/1999/XSL/Transform, cannot use this element. See , msxslt:script.
Syntax
<xsl:script
language="language-name" >
</xsl:script>
Attributes
language
Active Scripting language used for the functions defined within this element. If left unspecified, the current scripting language is used, as specified by a language attribute on an ancestor. If no such attribute exists, JScript® (compatible with ECMA 262 language specification) is used. This attribute accepts the same values as the language attribute on the HTML SCRIPT element.
Element Information
Number of occurrences | Unlimited |
Parent elements | xsl:stylesheet |
Child elements | (No child elements) |
Requires closing tag | Yes. XSL is an XML grammar and, like all XML grammars, all tags must have closing tags to satisfy the definition of well-formed. |
Remarks
You can declare variables and define functions within the xsl:script element. This can appear within the xsl:stylesheet or xsl:template elements. A script block thus nested is treated as a global script block.
In Internet Explorer version 5.01, you can also instantiate COM objects in the xsl:script element. However, a user's security settings may prevent your script from instantiating a client-side object.
Example
This example shows a simple style sheet that converts the value of 32 degrees Fahrenheit to Celsius and inserts this value into the output.
The xsl:script element contains the function definition and creates an instance of myTemperatureObject , which processes the data. The xsl:eval element inserts the value returned from the function into the output. The language attribute indicates that the scripting language used in this style sheet is VBScript.
<xsl:stylesheet language="VBScript">
<xsl:template match="/">
<xsl:eval>Celsius(32)</xsl:eval>
</xsl:template>
<xsl:script>
Function Celsius(fDegrees)
Set Temperature = CreateObject("myTemperatureObject")
Temperature.Fahrenheit = fDegrees
GetCelsius = Temperature.Celsius
End Function
</xsl:script>
</xsl:stylesheet>
See Also