When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML Info
Information:
Advertise
Feedback
Author an Article
Technology Jobs

















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this page.

Windows Systems Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

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"?>
<memo>
  <from>Arno Jansen</from> 
  <to>XML developers</to>
  <subject>Little XML example</subject>
  <message>This is a small XML example using HTML forms</message>
</memo>

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
</A>

for viewing and like this for editing:

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

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:

  xmlDocument.load(Server.Mappath(memofile))
  xslDocument.load(Server.Mappath(stylesheet))

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.

  Response.Write(xmlDocument.transformNode(xslDocument))

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


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



  • JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES