Microsoft KB Archive/273793

= How To Include Client-Side Script Functions in an XSL Document =

Article ID: 273793

Article Last Modified on 8/8/2007

-

APPLIES TO


 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Explorer 5.01
 * Microsoft Internet Explorer (Programming) 5.01 SP1
 * Microsoft Internet Explorer 5.5

-



This article was previously published under Q273793



SUMMARY
When you return HTML from an XML/XSL transform, you often have to return SCRIPT blocks. For example:  function someFunction {            //Your code here. }  This article describes how you can include the DEFER attribute for the  tag when you include a script function in an XSL document that is used in a client-side XML/XSL transform.

NOTE: You only need the DEFER attribute when you manually perform the XML/XSL transform in client-side script. You do not need this attribute in a server-side XML transform, or if the transform is performed when navigating to a static XML file that links to the XSL document.



MORE INFORMATION
If you do not include the DEFER attribute for the  tag, and the function is called from the transformed document, an &quot;Object Expected&quot; error occurs.

In addition, you must enclose the SCRIPT block in  tags and a CDATA section. If you do not wrap the script in a CDATA section, the XML parser parses the contents of the SCRIPT block. Because script can contain reserved characters, such as &quot;<&quot; and &quot;>&quot;, the CDATA section protects the parser from potentially invalid XML within the SCRIPT block.

Sample Code
NOTE: Make sure that you save the following files in the same folder.   Create a new XML file named Xmldoc.xml, and then paste the following code:  Hello World

  Create a new XSL file named Xsldoc.xsl, and then paste the following code:    <HTML> <BODY> <SCRIPT LANGUAGE=&quot;javascript&quot; DEFER=&quot;true&quot;> <xsl:comment> <![CDATA[ function hiLite {      alert(&quot;hello&quot;); }     ]] >     </xsl:comment> </SCRIPT> <INPUT id=&quot;BUTTON1&quot; name=&quot;BUTTON1&quot; onclick=&quot;hiLite&quot; type=&quot;button&quot; value=&quot;aTest&quot;/> </BODY> </HTML> </xsl:template> </xsl:stylesheet> IMPORTANT: For the preceding code to work in Internet Explorer, you must delete the space between the bracket (]) and the greater-than symbol (>) in the following line: ]] > It was necessary to include this space to format the code in this article. </li>  Create a new HTML file named Demo.htm, and then paste the following code: <SCRIPT language=&quot;JavaScript&quot;>

<input type=button onclick=&quot;transformDoc&quot; value=&quot;Transform&quot;> </li> In Internet Explorer, open Demo.htm, and then click Transform.</li> To fire the function that is applied to the document from the transformation, click Test Scripting. A button with lable aTest is displayed.</li> To fire the function, click aTest. An alert is displayed.</li></ol>

<div class="references_section">