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



The information in this article applies to:

  • Microsoft XML 2.0
  • Microsoft ASP.NET (included with the .NET Framework 1.1)
  • Microsoft ASP.NET (included with the .NET Framework) 1.0
  • Microsoft XML Classes (included with the .NET Framework 1.1)
  • Microsoft XML Classes (included with the .NET Framework 1.0)

This article was previously published under Q315888

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 How to apply an XSL transformation to XML for streaming by using Visual Basic .NET

300929 How to apply an XSL transformation from an XML document to an XML document by using Visual Basic .NET


Modification Type:MinorLast Reviewed:11/8/2005
Keywords:kbHOWTOmaster kbWebForms KB315888 kbAudDeveloper