Link to home
Start Free TrialLog in
Avatar of racing_chicken
racing_chicken

asked on

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

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
  source.load(sourceFile);

  // Load the XSLT
  var style = Server.CreateObject("Msxml2.DOMDocument");
  style.async = false;
  style.resolveExternals = false
  style.load(styleFile);
  Response.Write(source.transformNode(style));
%>

"XML Document"
<?xml version="1.0" standalone="yes"?>
<Catalog xmlns="/schema">
  <Item>
    <ID>3</ID>
    <Name>Aniseed Syrup</Name>
    <Price>10</Price>
    <Stock>13</Stock>
  </Item>
  <Item>
    <ID>40</ID>
    <Name>Boston Crab Meat</Name>
    <Price>18.4</Price>
    <Stock>123</Stock>
  </Item>
</Catalog>

"XSL document"
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
  <xsl:template match="/">
  <HTML>
    <BODY>
      <TABLE BORDER="2">
        <TR>
          <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>
        </TR>
      <xsl:for-each select="Catalog/Item">
        <TR>
          <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>
        </TR>
      </xsl:for-each>
      </TABLE>
      </BODY>
    </HTML>
  </xsl:template>
</xsl:stylesheet>

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?
Avatar of StuF
StuF

Hi,

Could you try:

  style.load(styleFile);
  Response.Write(source).selectSingleNode('Catalog/Item[ID=3]').transformNode(style)

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

source.load(sourceFile);
source.selectNodes['Catalog/Item[ID!=3]'].removeAll()

Not sure if these will work but its worth a go

Have fun
StuF
Avatar of racing_chicken

ASKER

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.

R.C.
ASKER CERTIFIED SOLUTION
Avatar of StuF
StuF

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.