Magazine |
| | Community |
| | Workshop |
| | Tools & Samples |
| | Training |
| | Site Info |
|
|
||||||||
|
January 7, 1998
The XSL ActiveX control allows XML data to be displayed within an HTML page using an XSL stylesheet. It is not necessary to install the XSL ActiveX control; its installation is automatic.
To enable the XSL ActiveX control, all you need to do is place the following <OBJECT> in your HTML document:
<OBJECT ID="XSLControl" CLASSID="CLSID:2BD0D2F2-52EC-11D1-8C69-0E16BC000000" codebase="http://www.microsoft.com/xml/xsl/msxsl.cab" style="display:none"> </OBJECT>
This object will cause the XSL ActiveX control to be downloaded and installed automatically. Two DLLs are registered: MSXSL.DLL, the core XSL processor, and XSLCTRL.DLL, the ActiveX wrapper. In addition, ATL.DLL will be installed if it is not already present on the machine.
Hint: To create an XSLCTRL object, you must have the particular CLASSID and CODEBASE shown above. The easiest way to retrieve this information is to cut and paste the whole <OBJECT> above into your page.
The XSL ActiveX control has one property which sets the URL of the XML document to be processed (documentURL) and another which sets the URL of the XSL stylesheet (styleURL).
You may place <PARAM> tags within the <OBJECT> to set the initial state of the documentURL and styleURL properties and cause the download of the associated files.
<OBJECT ID="XSLControl" CLASSID="CLSID:2BD0D2F2-52EC-11D1-8C69-0E16BC000000" CODEBASE="http://www.microsoft.com/xml/xsl/msxsl.cab" STYLE="display:none"> <PARAM NAME="documentURL" VALUE="sample.xml"> <PARAM NAME="styleURL" VALUE="sample.xsl"> </OBJECT>
The XSL ActiveX control supports a property (htmlText) that processes the XML source document using the XSL stylesheet and returns the results of that processing as an HTML string.
For example, the following <SCRIPT> element
<SCRIPT FOR=window EVENT=onload> var xslHTML = XSLControl.htmlText; document.all.item("xslTarget").innerHTML = xslHTML; </SCRIPT>
inserts the resulting HTML string into the "xslTarget" element, which might be defined as something like
<DIV id=xslTarget></DIV>
The code above is incorporated into a simple demo that loads sample.xml and sample.xsl and displays the results.
Try the Simple XSL ActiveX Control Demo. (Requires Windows 95 or Windows NT and Internet Explorer 4.0
.)
The documentURL and styleURL properties may be called from script as well. The following example functions may be used within a document to change data or stylesheets and then update the HTML page with the results.
<SCRIPT> function changeDocumentURL(newURL) { XSLControl.documentURL = newURL; document.all.item("xslTarget").innerHTML = XSLControl.htmlText; } function changeStyleXSL(newURL) { XSLControl.styleURL = newURL; document.all.item("xslTarget").innerHTML = XSLControl.htmlText; } </SCRIPT>
Note: The documentURL and styleURL properties can be both read and set.
The code above is incorporated into a demo that sets the data and style URLs individually and displays the results.
Try the XML/XSL Viewer Demo. (Requires Windows 95 or Windows NT and Internet Explorer 4.0
.)
Did you find this article useful? Gripes? Compliments? Suggestions for other articles? Write us!
© 1998 Microsoft Corporation. All rights reserved. Terms of use.