Click to return to the XML (Extensible Markup Language) home page    
xsl:pi Element     xsl:stylesheet Element     XSL Elements    
Web Workshop  |  XML (Extensible Markup Language)

xsl:script Element


Defines global variables and functions for script extensions.

Syntax

<xsl:script
    language="language-name"  >

Attributes

language
Active Scripting language used for the 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

Calling Script During Transformation, XSL Methods



Back to topBack to top

Did you find this topic useful? Suggestions for other topics? Write us!

© 1999 Microsoft Corporation. All rights reserved. Terms of use.