How do I navigate to different areas of my XML document using my .asp web page?

Posted on 2005-04-21
Last Modified: 2010-04-06
I am using the following .asp page to generate html code from my xml document.

".asp page"
<%@ LANGUAGE = JavaScript %>
  // Set the source and style sheet locations here
  var sourceFile = Server.MapPath("catalog.xml");
  var styleFile = Server.MapPath("catalog.xsl");

  // Load the XML
  var source = Server.CreateObject("Msxml2.DOMDocument");
  source.async = false;
  source.resolveExternals = false

  // Load the XSLT
  var style = Server.CreateObject("Msxml2.DOMDocument");
  style.async = false;
  style.resolveExternals = false

"XML Document"
<?xml version="1.0" standalone="yes"?>
<Catalog xmlns="/schema">
    <Name>Aniseed Syrup</Name>
    <Name>Boston Crab Meat</Name>

"XSL document"
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="">
  <xsl:template match="/">
      <TABLE BORDER="2">
          <TD><P ALIGN="center"><B>ID</B></P></TD>
          <TD><P ALIGN="center"><B>Name</B></P></TD>
          <TD><P ALIGN="center"><B>Price</B></P></TD>
          <TD><P ALIGN="center"><B>Stock</B></P></TD>
      <xsl:for-each select="Catalog/Item">
          <TD><xsl:value-of select="ID" /></TD>
          <TD><xsl:value-of select="Name" /></TD>
          <TD><xsl:value-of select="Price" /></TD>
          <TD><xsl:value-of select="Stock" /></TD>

This is just a model, but it works.  What I would like to do is to access different areas of my XML data to create different html pages.  How can I go about it. Is there some way to do it using the url to the .asp file.  e.g or something along those lines? Are there other options?
Question by:racing_chicken
    LVL 1

    Expert Comment


    Could you try:


    or After the source has been loaded then remove all unrequired nodes


    Not sure if these will work but its worth a go

    Have fun

    Author Comment

    Thanks Stuf, but I'm looking for a different solution.

    When there is more data, I want to be able to generate different html pages on my website, with different data from my XML document,  based solely on what paramenters I add to the url I enter into the browser. I know it can be done, I just don't know how. It may involve xpath or xpointer, or not, I don't really know.

    Let's say my XML is team stats. would show me team 1's stats while would show me team 2's stats.

    the format for the parameters is just a guess.

    LVL 1

    Accepted Solution

    OK, two options

    first set the URL to be

    then change the code to be:

    var teamNumber = Request.Item("tm")
    source.selectNodes['Catalog/Item[ID!=' +teamNumber + ']'].removeAll()

    Alternatively use MSXML2.XSLTemplate and pass in a param in to the XSL

    First change the xsl to have
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="">
    <xsl:param name="TeamNumber"/>
    <xsl:for-each select="Catalog/Item[ID=$TeamNumber]">

    Now change the asp to have

    // Create the XSL Template
    var oXSLtemplate = new  Server.CreateObject('MSXML2.XSLTemplate');
    // Set the stylesheet to be the DOM
    oXSLtemplate.stylesheet = style

    // Create the Processor
    var teamNumber = Request.Item("tm")
    var processor = oXSLtemplate.createProcessor();
    // Set the processor input to be the source DOM
    processor.input = source
    var output = processor.output;

    Would this be any better



    Author Comment

    Thank you StuF,  you set me on the right path.  Along the way I changed the problem a little, but I solved it.  The second solution was the most help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Highfive + Dolby Voice = No More Audio Complaints!

    Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

    Preface In the first article: A Better Website Login System ( I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
    I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now