Microsoft Knowledge Base Email Alertz

(315888) - This step-by-step article demonstrates how to create a generic ASP.NET Web form that you can use to evaluate the outcome of using different XSLT documents to transform XML documents without adding or modifying an ?xml-stylesheet? processing...

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: 315888 - Last Review: November 8, 2005 - Revision: 3.5

How to create a generic ASP.NET Web form to test XSLT transformations

This article was previously published under Q315888

On This Page

SUMMARY

This step-by-step article demonstrates how to create a generic ASP.NET Web form that you can use to evaluate the outcome of using different XSLT documents to transform XML documents without adding or modifying an <?xml-stylesheet?> processing instruction in the XML documents.

Running XSLT transformations by loading and processing specified XML and XSLT documents is a common functionality in XML-based ASP.NET Web applications.

Creating the ASP.NET Web form

  1. Create a new Microsoft Visual Basic ASP.NET Web Application project that is named GenericXSLT by using Visual Studio .NET.
  2. Drag a Web Forms XML control from the toolbox on WebForm1.aspx.
  3. Specify XmlTransform as the value for the XML control's ID property.
  4. Right-click the designer surface of WebForm1.aspx, and then click View Code to edit the code in the Web form's code behind class module WebForm1.aspx.vb.
  5. Paste the following code in the Page_Load sub procedure:
    XmlTransform.DocumentSource = Request.QueryString("xml")
    XmlTransform.TransformSource = Request.QueryString("xsl")
    					
  6. Save the changes to WebForm1.aspx.vb.

Creating the sample XML document

  1. Add a new XML file named Books.xml to the GenericXSLT ASP.NET Web project, and then place the following code in the file. (Use Notepad as an intermediary if you encounter any encoding or character problems when you try to paste the following code.)
    <?xml version="1.0"?>
    <Books>
    <Book>
     <Title>Beginning XML</Title>
     <Author>John</Author>
    </Book>
    <Book>
     <Title>Mastering XML</Title>
     <Author>Peter</Author>
    </Book>
    </Books>
    					
  2. Save the changes to Books.xml, and then close the Visual Studio .NET XML editor window.

Creating the sample XSLT document

  1. Add a new XSLT file named Books.xslt to the GenericXSLT ASP.NET Web project, and the paste the following code in the file. (Use Notepad as an intermediary if you encounter any encoding or character problems when you try to 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>
    					
  2. Save the changes to Books.xslt, and then close the Visual Studio .NET XML/XSLT editor window

Testing XSLT transformations by using the ASP.NET Web form

  1. Save the changes to the GenericXSLT ASP.NET Web project.
  2. Build the GenericXSLT ASP.NET Web project.
  3. Start Microsoft Internet Explorer, and then browse to WebForm1.aspx by specifying the following URL, where IISServerName is the name of your Microsoft Internet Information Services (IIS) server:
    http://IISServerName/GenericXSLT/WebForm1.aspx?xml=Books.xml&xsl=Books.xslt
    The output from applying the Books.xslt XSLT style sheet to the Books.xml XML document is displayed in Internet Explorer. The data in Books.xml is formatted and displayed as an HTML table.
  4. You can test the output of transforming other XML documents with their associated XSLT style sheets by specifying their names as the xml and the xsl querystring parameters in the URL to access the WebForm1.aspx ASP.NET Web form. You must specify the relative paths to the documents if they are not located in the same folder as the .aspx Web form.

REFERENCES

For more information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
300934  (http://kbalertz.com/Feedback.aspx?kbNumber=300934/ ) How to apply an XSL transformation to XML for streaming by using Visual Basic .NET
300929  (http://kbalertz.com/Feedback.aspx?kbNumber=300929/ ) How to apply an XSL transformation from an XML document to an XML document by using Visual Basic .NET

APPLIES TO
  • Microsoft XML Parser 2.0
  • Microsoft ASP.NET 1.1
  • Microsoft ASP.NET 1.0
  • Microsoft .NET Framework 1.1
  • Microsoft .NET Framework 1.0
Keywords: 
kbhowtomaster kbwebforms KB315888
       

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