Microsoft HomeproductssearchsupportshopWrite Us   Microsoft Home
Magazine
 |  Community
 |  Workshop
 |  Tools & Samples
 |  Training
 |  Site Info

Workshop  |  XML (Extensible Markup Language)

Using the Microsoft XSL ActiveX Control in a Web Page


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.


Step 1: Place an OBJECT tag in the Web page

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.

Step 2: Point the XSLCTRL to the XML document and XSL stylesheet

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>


Step 3: Insert the resulting HTML into your page

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>


Step 4: Try it out

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 Non-SBN link.)

DownloadDownload the files used by this demo (zipped, 1.7K).


Step 5: Changing the XML document and XSL stylesheet URLs

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.

Step 6: Try it out (part 2)

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 Non-SBN link.)

DownloadDownload the files used by this demo (zipped, 73K).

HomeBack to the XSL home page


Did you find this article useful? Gripes? Compliments? Suggestions for other articles? Write us!

Back to topBack to top

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

 

Magazine Home
Ask Jane
DHTML Dude
Extreme XML
For Starters
More or Hess
Servin' It Up
Site Lights
Web Men Talking
Member Community Home
Benefits: Freebies & Discounts
Benefits: Promote Your Site
Benefits: Connect with Your Peers
Benefits at a Glance
Online Special-Interest Groups
Your Membership
SBN Stores
Join Now
Workshop Home
Essentials
Content & Component Delivery
Component Development
Data Access & Databases
Design
DHTML, HTML & CSS
Extensible Markup Language (XML)
Languages & Development Tools
Messaging & Collaboration
Networking, Protocols & Data Formats
Reusing Browser Technology
Security & Cryptography
Server Technologies
Streaming & Interactive Media
Web Content Management
Workshop Index
Tools & Samples Home
Tools
Samples, Headers, Libs
Images
Sounds
Style Sheets
Web Fonts
Training Home
SBN Live Seminars
SBN Live Chats
Courses
Peer Support
CD-ROM Training
Books & Training Kits
Certification
SBN Home
New to SBN?
What's New on SBN
Site Map
Site Search
Glossary
Write Us
About This Site