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: Wednesday, June 07, 2000

Displaying XML Data from other Web Sources as HTML using XSL, Part 4

By Brandon Monahan

  • Read Part 1
  • Read Part 2
  • Read Part 3

  • In Part 3 we looked at some of the more advanced abilities of XSL, such as how to iterate through XML nodes and how to display hyperlinks. In this part we'll look at one possible way to use XSL to display the XML generated by iSyndicate.com!

    - continued -

    Now we have got the ability to loop through our XML, we can display all kinds of data and make hyperlinks. What more do you need to know? Here is the finished XSL document using all of the information above (by the way, the header, stylesheet, and template tags are all necessary for any XSL document transferring the HTML):

    <?xml version='1.0'?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    <xsl:template match="/">
    <xsl:for-each select="newsfeed/channel">
          <td colspan="2">
            <font face="arial" size="1">
            <xsl:value-of select="@title"/>
      <xsl:for-each select="headline">
           <td valign="top">
             <font face="arial" size="1">
             <xsl:attribute name="href">
             <xsl:value-of select="@href"/>
             <xsl:value-of />

    This code will simply loop through the channels displaying the channel name, then inside loop through the headlines in that channel giving the headline name and a link to the news. To see this XSL stylesheet in action be sure to view the live demo!

    How do I Make it All Work?
    First, take the above XSL code and save it to your server. I saved it as home_News.xsl. Now that you have completed that, let's go back to the ASP.

      set xml = Server.CreateObject("Microsoft.XMLDOM")

    In the above code we had initiated the XML DOM object and loaded the external XML document. Now let's instantiate the XSL DOM object and load our XSL document like such:

      set xsl = Server.CreateObject("Microsoft.XMLDOM")

    Now we are almost finished. All we have to do is write the parsed XML to the page and clean up like such:

      xsl = nothing
      xml = nothing

    That's that. Your XML should be written to the page as a beautifully formatted block of news stories (html). More likely than not, you will get a blank screen. Here is how to fix that.

    XML and XSL are really easy to debug. Just grab the file and drag it to your IE 5 browser. If you made an error, it will tell you what you did wrong and where. Make the correction and refresh. Keep doing that until it display your XSL and XML documents correctly. After that, give your ASP page a try again. Hopefully it will work this time.

    There are a couple of problems you may run into like not having the proper settings on the server to let your program load a document from another site. If you can't make it run on your server but you are sure you have the code correct give it a try on PWS (PWS doesn't have the features of such complicated security and should run the page) or save the XML file to a local disk and give it a try.

    Final Product
    You can view almost this exact code being used in production at www.citiesunited.com or for just the page of HTML that is included on the home page go to www.citiesunited.com/home_News.asp.

    Good Luck and Happy Programming! If you have any questions, problems, or what-not, please do feel free to drop me a line at: bwm4@yahoo.com. If you found this article interesting be sure to check out the related articles listed below...

    Brandon Monahan


  • Download home_News.xsl
  • Download the source to home_News.asp in text format (this ASP page utlizes home_News.xsl to display the syndicated news)
  • View the live demo!

    Related Articles

  • Getting Started with XML
  • XML Links and Information

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