Microsoft Knowledge Base Email Alertz

(258294) - It is possible to offload XSL processing from the server to the client. Doing so distributes the load, which helps to relieve the server from having to process the formatting of an XML document.

Search KbAlertz

Advanced Search

Receive Microsoft Knowledge Base articles by E-Mail?

Every night we scan the Microsoft Knowledge Base. If technologies you're interested in are updated, we'll send you an e-mail. You only get one e-mail a day, and only when new articles are added.

Click here to create a
FREE account
Already have an account?
[Click here to Login]











Microsoft Knowledge Base Article

This article contents is Microsoft Copyrighted material.
©2005-©2007 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks

Article ID: 258294 - Last Review: October 20, 2009 - Revision: 3.0

How To Offload XSL Transformations to Clients' Browsers

This article was previously published under Q258294

SUMMARY

It is possible to offload XSL processing from the server to the client. Doing so distributes the load, which helps to relieve the server from having to process the formatting of an XML document.

MORE INFORMATION

The following example demonstrates how to load an XSL and XML document into the clients' memory and then it uses the XSL to transform the XML.
  1. First, copy the following code into a file named Sample.htm, and then save the file to a WebServer in a location accessible from the Web:
    <HTML>
    <HEAD>
    <TITLE>Clientside XSL Processing Sample</TITLE>
    <SCRIPT LANGUAGE="VBScript">
    	dim xslDoc, xmlDoc
    
    Use the Version dependent PROGID 'MSXML2.DOMDocument.6.0 if you wish to use the DOMDocument object that ships with MSXML 6.0.	
    
    	Sub Init()
    		set xslDoc = CreateObject("Microsoft.XMLDOM")
    		set xmlDoc = CreateObject("Microsoft.XMLDOM")
    		xslDoc.Async = False
    		xmlDoc.Async = False
    		xslDoc.Load "http://<YourServerName>/Sample.xsl"
    		xmlDoc.Load "http://<YourServerName>/Sample.xml"
    		Data.innerHTML = xmlDoc.transformNode(xslDoc)	
    	End Sub
    </SCRIPT>
    </HEAD>
    <BODY ONLOAD="Init">
    <CENTER><H1>Clientside XSL Processing Sample</H1></CENTER>
    <DIV ID="Data">
    </DIV>
    </BODY>
    </HTML>
    					
  2. Modify the page so that the address of the Sample.xml and Sample.xsl files is the same as the location of your server.
  3. Insert the following XML code into a blank XML document and save it to the same location as the Sample.xml file:
    <?xml version="1.0"?>
    <CUSTOMERS>
       <CUSTOMER>
          <CustomerID>
             ALFKI
          </CustomerID>
          <CompanyName>
             Alfreds Futterkiste
          </CompanyName>
          <ContactName>
             Maria Anderson
          </ContactName>
          <Country>
             Germany
          </Country>
       </CUSTOMER>
       <CUSTOMER>
          <CustomerID>
             ANATR
          </CustomerID>
          <CompanyName>
             Ana Trujillo Emparedados y helados
          </CompanyName>
          <ContactName>
             Ana Trujillo
          </ContactName>
          <Country>
             Mexico
          </Country>
       </CUSTOMER>
    </CUSTOMERS>
    					
  4. If using an MSXML version earlier than 3.0, then insert the following XSL code into a blank XSL document and save it to the same location as the Sample.xsl file.
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">   
       <xsl:template match="http://support.microsoft.com/Books"> 
               <HTML>
               <BODY>
               <TABLE BORDER="2">
                 <TR>
                   <TD>Title</TD>
                   <TD>Author</TD>
                 </TR>
                 <xsl:for-each select="Book">
                   <TR>
                     <TD><xsl:value-of select="Title"/></TD>
                     <TD><xsl:value-of select="Author"/></TD>
                   </TR>
                 </xsl:for-each>
               </TABLE>     
               </BODY>
         </HTML>    
         </xsl:template>     
       </xsl:stylesheet>
    					
  5. Browse to the Sample.htm page.
This page loads into the browser, and then downloads the data for the XML and XSL pages. It then uses the XSL document to transform the XML document into HTML. It displays this output on the page by using the innerHTML property of the DIV tag on the HTML page.

APPLIES TO
  • Microsoft Internet Information Server 4.0
  • Microsoft XML Parser 2.0
  • Microsoft XML Parser 2.5
  • Microsoft XML Parser 2.6
  • Microsoft XML Parser 3.0
  • Microsoft XML Core Services 4.0
  • Microsoft XML Core Services 6.0
Keywords: 
kbhowto KB258294
       

Community Feedback System

Very often, it takes hours to solve a problem. Very often, you've looked high and low, and have tried a lot of solutions. When you finally found it, chances are, it was because someone else helped you. Here's your chance to give back. Use our community feedback tool to let others know what worked for you and what didn't.

Please also understand that the community feedback system is not warranted to be correct, it's simply a system that we've built to let people try and help each other. If something in a feedback response doesn't make sense to you, or you're not comfortable making changes that the feedback talks about (like registry edits), please consult a professional.

Thank you for using kbAlertz.com Feedback System.

-- Scott Cate