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

Posted on 2005-04-21
Medium Priority
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="http://www.w3.org/TR/WD-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 http://domain.com/start.asp?ID=3 or something along those lines? Are there other options?
Question by:racing_chicken
  • 2
  • 2

Expert Comment

ID: 13843536

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

ID: 13845159
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.

www.teamstats.com/start.asp?stats&tm1 would show me team 1's stats while
www.teamstats.com/start.asp?stats&tm2 would show me team 2's stats.

the format for the parameters is just a guess.


Accepted Solution

StuF earned 2000 total points
ID: 13857790
OK, two options

first set the URL to be www.teamstats.com/start.asp?stats&tm=1

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="http://www.w3.org/TR/WD-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

ID: 13883341
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.

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It's sometimes a bit tricky to use date functions in Oracle BPEL. I'll explain quickly how you can add N days to the current date. In a BPEL process this can be useful, and you can adapt it to fit your needs. First of all, let's see how to add 1 …
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

599 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