Editor’s note: This article originally appeared in TechRepublic’s Web Development Zone TechMail. Subscribe, and you’ll receive information on Web-development related projects and trends.

By Les Hamilton

The problem with using Extensible Markup Language (XML) and Extensible Stylesheet Language (XSL) on the Web is that only Internet Explorer 5 and above can display it. While this is acceptable for intranets and public Web sites, where we can specify the use of IE5+ for our clients, what about those times when you want to make the same content available for Netscape or handheld users? A lot of developers have been forced to write and test their Web sites two or more times in order to achieve proper display formatting for their company’s sites.

Second in a series

This article from TechRepublic’s Web Development Zone describes issues related to integrating XML and Active Server Pages (ASP). Last week’s article discussed XML and XSL integration. Next week’s installment will look at XML, ActiveX Data Objects (ADO), and ASP.

Thanks to the foresight of Microsoft, it is possible to combine the XML and XSL on the server and send the resulting HTML code to a client browser. By using the Msxml3.dll in an ASP page, we can load and transform an XML document with an XSL style sheet and send the results to our users. Here is a shortened example (leaving out most of the error handling code) of the needed code for a Sample.asp.
<%@ LANGUAGE = JScript %>
  // Set the source and stylesheet locations here
  var sourceFile = Server.MapPath(“sample.xml”);
  var styleFile = Server.MapPath(“sample.xsl”);
  // Load the XML
  var source = Server.CreateObject(“Microsoft.XMLDOM”);
  source.async = false;

  // Load the XSL
  var style = Server.CreateObject(“Microsoft.XMLDOM”);
  style.async = false;
  result = source.transformNode(style);


To run this ASP page, you need to have the Internet Explorer 5 Msxml.dll installed on your server. Create a test site on your machine and try viewing the ASP page and the XML files.

Below are the Sample.xsl file source and the Sample.xml that we want to present.

<?xml version=”1.0″?>
<HTML xmlns:xsl=”http://www.w3.org/TR/WD-xsl”>
  <BODY STYLE=”font-family:Arial, helvetica, sans-serif; font-size:12pt;
    <xsl:for-each select=”breakfast-menu/food”>
      <DIV STYLE=”background-color:teal; color:white; padding:4px”>
        <SPAN STYLE=”font-weight:bold; color:white”>
        <xsl:value-of select=”name”/></SPAN>
        – <xsl:value-of select=”price”/>
      <DIV STYLE=”margin-left:20px; margin-bottom:1em; font-size:10pt”>
        <xsl:value-of select=”description”/>
        <SPAN STYLE=”font-style:italic”>
          (<xsl:value-of select=”calories”/> calories per serving)

<?xml version=’1.0′?>
<?xml:stylesheet type=”text/xsl” href=”simple.xsl” ?>
    <name>Belgian Waffles</name>
    <description>two of our famous Belgian Waffles with plenty
    of real maple syrup</description>
    <name>Strawberry Belgian Waffles</name>
    <description>light Belgian waffles covered with strawberrys
    and whipped cream</description>
    <name>Berry-Berry Belgian Waffles</name>
    <description>light Belgian waffles covered with an assortment
    of fresh berries and whipped cream</description>
    <name>French Toast</name>
    <description>thick slices made from our homemade sourdough
    <name>Homestyle Breakfast</name>
    <description>two eggs, bacon or sausage, toast, and our
    ever-popular hash browns</description>

For more information, check out MSDN Online—XML Developer Center.