ASP 101 - Active Server Pages 101 - Web06
The Place ASP Developers Go!

Please visit our partners

Windows Technology Windows Technology
15 Seconds
ASP 101
ASP Wire
VB Forums
VB Wire
internet.commerce internet.commerce
Partners & Affiliates

ASP 101 is an site
ASP 101 is an site
Internet News
Small Business
Personal Technology

Corporate Info
Tech Jobs
E-mail Offers

ASP 101 News Flash ASP 101 News Flash

ASP.NET version of "XML to HTML (via XSL)"

This sample script takes an XML file and an XSL file and combines them to produce whatever output you want. The sample files we use simply take some of our sample data and convert it to a basic HTML table, but you can use the same code to convert your data to whatever format you want... just by changing the stylesheet.

For the most part the code in this sample is pretty straight-forward. The only exception is the use of the Stringbuilder. The Transform method of the XslTransform object doesn't output its result as a simple string. So... in order to get a string that we can bind to our Literal control, we create a StringBuilder and then connect a StringWriter to it. This way the Transform method can pass its output to the StringWriter which is connected to our StringBuilder. From there we simply us the StringBuilder's ToString method to retrieve our String.

Here's a zip file of the code (2.1 KB).

Play with the running version.

View the live source code.

Update: ASP.NET's XML Control

If you're looking for an even simpler method, check out ASP.NET's built in XML control. I'm not sure I ever knew that it existed, but, if I did, I forgot all about it until I was browsing Microsoft's ASP.NET Quickstart and ran across it. What took me probably a dozen lines of code to do, this little control does for you for nothing! I've added the script to the zip file above.

Play with the running version.

View live source code.

Using Remote XML/XSL Files

If you're going to be pulling either the XML of XSL file from a remote server, you should take a look at the remote version of this sample: XML to HTML (via XSL) - Remote Files.

Back to the "XML to HTML (via XSL)" sample


Home |  News |  Samples |  Articles |  Lessons |  Resources |  Forum |  Links |  Search |  Feedback
The Network for Technology Professionals



Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers