Microsoft KB Archive/315888

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

Article ID: 315888

Article Last Modified on 11/8/2005

-

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

-



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  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
 Create a new Microsoft Visual Basic ASP.NET Web Application project that is named GenericXSLT by using Visual Studio .NET. Drag a Web Forms XML control from the toolbox on WebForm1.aspx. Specify XmlTransform as the value for the XML control's ID property. 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.  Paste the following code in the Page_Load sub procedure: XmlTransform.DocumentSource = Request.QueryString(&quot;xml&quot;) XmlTransform.TransformSource = Request.QueryString(&quot;xsl&quot;)  Save the changes to WebForm1.aspx.vb.</li></ol>

Creating the sample XML document
<ol>  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=&quot;1.0&quot;?> <Books> <Book> <Title>Beginning XML</Title> <Author>John</Author> </Book> <Book> <Title>Mastering XML</Title> <Author>Peter</Author> </Book> </Books> </li> Save the changes to Books.xml, and then close the Visual Studio .NET XML editor window.</li></ol>

Creating the sample XSLT document
<ol>  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=&quot;1.0&quot; xmlns:xsl=&quot;http://www.w3.org/1999/XSL/Transform&quot;> <xsl:template match=&quot;Books&quot;> <HTML> <BODY> </BODY> </HTML> </xsl:template> </xsl:stylesheet> </li> Save the changes to Books.xslt, and then close the Visual Studio .NET XML/XSLT editor window</li></ol>

Testing XSLT transformations by using the ASP.NET Web form
<ol> Save the changes to the GenericXSLT ASP.NET Web project.</li> Build the GenericXSLT ASP.NET Web project.</li> Start Microsoft Internet Explorer, and then browse to WebForm1.aspx by specifying the following URL, where  is the name of your Microsoft Internet Information Services (IIS) server:

http:// /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.</li> 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.</li></ol>

<div class="references_section">