When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles
Message Board
Related Web Technologies
User Tips!
Coding Tips

Sample Chapters
Commonly Asked Message Board Questions
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Stump the SQL Guru!
XML Info
Author an Article
ASP ASP.NET ASP FAQs Message Board Feedback
Print this page.
Published: Sunday, August 13, 2000

Online Content Creation using ASP, XML and XSL

By Arno Jansen

This article will describe a simple example on how XML can be used in combination with ASP and XSL to let surfers create content online. I assume you already know what XML and XSL are and how parsing of an XML is handled (in tree structure). If you don't, I have written a detailed explanation of the XML document and how the XSL stylesheets are used to translate the XML data to HTML: Using XSL Stylesheets to Translate XML into HTML. Also I would highly recommend that you read the articles in the XML Article Section on 4Guys.

- continued -

Imagine we are assigned a job to enable visitors of a website to create their own content. The "rules of engagement" are to use ASP for the dynamic part and XML to model the data. Of To keep the project as a whole simple to overview, I designed a small application that uses XSL stylesheets to translate the XML data to HTML. I then created two stylesheets, one for presenting the XML data into a viewable HTML file and one to translate it to an HTML form to let surfers edit the contents.

For this article we will use an XML file that contains a memo structure which contains a FROM field, a TO field, a SUBJECT line and the MESSAGE. The XML file for this structure looks like this:

<?xml version="1.0"?>
  <from>Arno Jansen</from> 
  <to>XML developers</to>
  <subject>Little XML example</subject>
  <message>This is a small XML example using HTML forms</message>

As I already described, we have two stylesheets: one for viewing and one for editing the memo. Because we want to use both stylesheets, we cannot specify a stylesheet in the XML file itself and send that file to the surfer's browser. Also, currently most browsers do not support XML (fully), so the ideal situation would be to process the XML file and one of the two stylesheets and just send the HTML output to the client. To accomplish that, we are going to use an ASP file that does the processing for us. We can link to the ASP file and supply one parameter on the querystring to let it know in what mode we want the memo to be (viewmode or edit mode), so a link would look something like this:

<A HREF="processmemo.asp?mode=view>
   Memo in View mode

for viewing and like this for editing:

<A HREF="processmemo.asp?mode=edit>
   Memo in Edit mode

Now, let's have a look at the ASP file (processmemo.asp) that is responsible for displaying either the XML data in either a viewable or editable mode. Before we start translating the XML into the appropriate HTML, we need to know in what mode we have to present the memo, so we use Request.QueryString to get the value of the mode. To get the right stylesheet for that mode, we add .xsl to it, and we have the filename of the stylesheet. So, in our case we named the two stylesheets: view.xsl and edit.xsl.

  stylesheet = request.querystring("mode")
  stylesheet = stylesheet & ".xsl"

Next step is to create two instances of the XML parser object, one for the memo-XML file and one for the XSL stylesheet (because XSL is in fact just another XML file).

  set xmlDocument = Server.CreateObject("Microsoft.XMLDOM")
  set xslDocument = Server.CreateObject("Microsoft.XMLDOM")

Then we parse both the memo XML file and the stylesheet file in their instances:


And finally apply the stylesheet to the memo file and send the result to the surfer's browser. This is done using the transformNode method which we give the stylesheet we just parsed.


Doing this, just HTML is sent to the browser of the surfer. This way, you can serve XML files to a browser that is not able to handle XML. This does, however, require a server that can handle XML. I used IIS in combination with an installation of IE 5 on the server. IE5 comes with the XML parser COM object. If you do not want to install IE5, but you do want the XML parser object, Microsoft provides a redistributable package of the package on their MSDN website on XML (http://msdn.microsoft.com/xml/default.asp).

Designing for Different Browsers
If you use server-side XML processing in combination with a browser detection mechanism, you can use different stylesheets to create HTML that utilizes the different browser capabilities.

In Part 2 we'll examine the ASP page this is responsible for both presenting the viewable and editable formats of the XML data!

  • Read Part 2

  • ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article