Microsoft Knowledge Base Email Alertz

KBAlertz.com: When you develop XML-based, server-side Active Server Pages (ASP) applications, it is a common programming requirement to load Extensible Markup Language (XML) and Extensible Stylesheet Language Transformation (XSLT) documents into instance

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]

Search KbAlertz

Advanced Search

Webmasters
Put kbAlertz on your website.
[ Click Here for more! ]





ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **


Bug Tracking Software
For bug tracking software or defect tracking software or issue tracking software, visit Axosoft.


Community Site



We Send hundreds of thousands of emails using ASP.NET Email



Expert Web Design & Graphic Design
Design44.com

ASP.NET 3.5 Web Hosting with Windows 2008 and SQL 2008: Click Here!
Discount ASP.NET Hosting
ASP.NET 2.0 and 3.5
Windows2008 and SQL2008
US and UK Hosting
The ad says 3 - but KBAlertz referrals get
** SIX MONTHS FREE **




Mentioned In








Microsoft Knowledge Base Article

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




Article ID: 301394 - Last Review: June 29, 2004 - Revision: 1.1

How To Create an Generic ASP Page to Test XSL Transformations

This article was previously published under Q301394

On This Page

SUMMARY

When you develop XML-based, server-side Active Server Pages (ASP) applications, it is a common programming requirement to load Extensible Markup Language (XML) and Extensible Stylesheet Language Transformation (XSLT) documents into instances of the Microsoft XML (MSXML) DOMDocument object and use an XSLT style sheet to programmatically transform the XML.

This article demonstrates how to create a generic ASP page that allows you to evaluate the outcome of using different XSLT documents to transform an XML document without adding or modifying an <?xml-stylesheet?> processing instruction in the XML document.

MORE INFORMATION

Step-by-Step Example

  1. In your favorite HTML editor, create a new ASP page named TransformXml.asp, and paste the following code:
    <% 
    Dim xmldoc 
    Dim xsldoc
    
    'Use the MSXML 4.0 Version dependent PROGID 
    'MSXML2.DOMDocument.4.0 if you wish to create
    'an instance of the MSXML 4.0 DOMDocument object
     
    Set xmldoc = Server.CreateObject("MSXML2.DOMDocument") 
    Set xsldoc = Server.CreateObject("MSXML2.DOMDocument")
    
    xmldoc.Load Server.MapPath(Request.QueryString("xml"))
    
    'Check for a successful load of the XML Document.
    if xmldoc.parseerror.errorcode <> 0 then 
      Response.Write "Error loading XML Document :" & "<BR>"
      Response.Write "----------------------------" & "<BR>"
      Response.Write "Error Code : " & xmldoc.parseerror.errorcode & "<BR>"
      Response.Write "Reason : " & xmldoc.parseerror.reason & "<BR>"
      Response.End 
    End If
    
    
    xsldoc.Load Server.MapPath(Request.QueryString("xsl"))
    
    'Check for a successful load of the XSL Document.
    if xsldoc.parseerror.errorcode <> 0 then 
      Response.Write "Error loading XSL Document :" & "<BR>"
      Response.Write "----------------------------" & "<BR>"
      Response.Write "Error Code : " & xsldoc.parseerror.errorcode & "<BR>"
      Response.Write "Reason : " & xsldoc.parseerror.reason & "<BR>"
      Response.End 
    End If
    
    Response.Write xmldoc.TransformNode(xsldoc)
    
    %>
    					
  2. Save TransformXml.asp in your default Web site (which is usually <drive>:\Inetpub\Wwwroot).
  3. Create a new XML file named Books.xml, and paste the following code:
    <?xml version="1.0"?>
    <Books xmlns="http://myserver">
    <Book>
     <Title>Beginning XML</Title>
     <Author>John</Author>
    </Book>
    <Book>
     <Title>Mastering XML</Title>
     <Author>Peter</Author>
    </Book>
    </Books>
    					
  4. Save Books.xml in your default Web site.
  5. Create a new XSL file named Books.xsl, and paste the following code:
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">   
       <xsl:template match="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>
    					
  6. Save Books.xsl in your default Web site.
  7. In Internet Explorer, type the following URL in the Address bar to browse to the ASP page:
    http://<MyWebServer>/TransformXml.asp?xml=Books.xml&xsl=Books.xsl
    where <MyWebServer> is the name of your Web server. This uses Books.xsl to evaluate the results of transforming Books.xml.
TransformXml.asp takes two input QueryString parameters. The xml QueryString parameter should specify the name of the XML document that is going to be transformed, and the xsl QueryString parameter should specify the name of the XSLT style sheet that will be applied to the XML document. The code in the ASP page loads the specified XML and XSL documents into instances of the MSXML DOMDocument object and programmatically runs the transformation. Any parser errors that are encountered while trying to load the XML or the XSL document are reported accordingly.

To test the outcome of applying another style sheet to the same XML document, modify the xsl QueryString parameter to point to a different style sheet and refresh the page. Similarly, to evaluate XSLT transformations that use other XML and XSL files, modify the xml QueryString and xsl QueryString parameters to point to the files that need to be tested.

REFERENCES

For additional information, click the article number below to view the article in the Microsoft Knowledge Base:
258294  (http://kbalertz.com/Feedback.aspx?kbNumber=258294/EN-US/ ) How To Offload XSL Transformations to Clients' Browsers

APPLIES TO
  • Microsoft XML Parser 2.6
  • Microsoft XML Parser 3.0
  • Microsoft XML Parser 3.0 Service Pack 1
  • Microsoft XML Core Services 4.0
  • Microsoft Active Server Pages 4.0
Keywords: 
kbhowto KB301394
       

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

Be the first to leave feedback, to help others about this knowledge base article.

(Optional) Name

(Optional) Public URL Or Email

Comments
No HTML -- Text Only Please