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.
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.