Jump to content

Diplaying Complex XML Data


zullok2b
 Share

Recommended Posts

I am new to XML and XSL so please be nice. :)I have been asked by a co-worker to take an xml report and display it on an asp site.i have ran through w3schools tutorials on xml and xsl, but this xml file is a bit more complex. i have attempted to code it but when i pull up the asp page it does not display the data. I have googled how to display this complex xml file, but i have been unable to solve it. I believe the problem is my XSL file since my asp page does display the correct number of nodes called filename, and it does loop through the asp loop the correct number of times. It seems to just not execute the xsl code. Could someone please tell me what i am doing wrong?XML File:

<?xml version="1.0" encoding="UTF-8"?><session xmlns="http://winscp.net/schema/session/1.0" name="string here" start="2010-03-31T17:00:00.791Z">  <download>	<filename value="file name here" />	<destination value="new file name" />	<result success="true" />  </download>  <download>	<filename value="file name here" />	<destination value="new file name" />	<result success="true" />  </download></session>

XSL File:

<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:output method="html" encoding="UTF-8"/><xsl:template match="filename"><html><body><table width="100%" border="1">  <THEAD>	<TR>	   <TD width="100%"><B>Filename</B></TD>	</TR>  </THEAD>   <TBODY>	<TR>		   <TD width="100%"><xsl:value-of select="@value" /></TD>	  	</TR>	  </TBODY></table></body></html></xsl:template></xsl:stylesheet>

ASP File:

<%@ Language=JScript%><html><head></head><body><%	// Grabe the Data	 var objXMLDoc = Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM");  	 objXMLDoc.async = false;  	 objXMLDoc.load(Server.MapPath("test.xml"));  	 	 //Grabe the xsl display file	 var xsl=Server.CreateObject("MICROSOFT.FreeThreadedXMLDOM");  	 xsl.async = false;  	 xsl.load(Server.MapPath("test.xsl"));	 	 //create a query that will select the node for us	 var xmlQuery="//filename";  	 var docHeadlines=objXMLDoc.documentElement.selectNodes(xmlQuery);	  	//iterate through the node to display the stored informaiton	var numNodes;  	numNodes=docHeadlines.length;  	Response.Write(numNodes); 	Response.Write("<br />Before Loop");	var nn;  	for(var i=0;i<numNodes;i++){  		nn = docHeadlines.nextNode(); 		Response.Write(nn.transformNode(xsl));  		Response.Write("<br />")		Response.Write("in Loop");	}	Response.Write("<br />after Loop");	 %>	 </body></html>

Link to comment
Share on other sites

The elements in the input XML are in the namespace http://winscp.net/schema/session/1.0, your stylesheet needs to take that into account by binding a prefix to that namespace and using that prefix to qualify element names.And it is not clear what exactly you want to achieve with your stylesheet and your classic ASP code as the ASP page already contains the HTML "html" and "body" element but then your stylesheet tries to create them too, and even for each "filename" element.So you might want to clarify what you want to achieve by showing us the HTML output you want the stylesheet to create for the XML input sample you posted.

Link to comment
Share on other sites

Here is what i would like to see :)

<%@ Language=JScript%><html><head></head><body><table width="100%" border="1">  <THEAD>	<TR>	   <TD width="100%"><B>Filename</B></TD>	</TR>  </THEAD>   <TBODY>	<TR>		   <TD width="100%">The Value of Filename</TD>	  	</TR>	<TR>		   <TD width="100%">The Value of Filename</TD>	  	</TR>	<TR>		   <TD width="100%">The Value of Filename</TD>	  	</TR>	<TR>		   <TD width="100%">The Value of Filename</TD>	  	</TR>	<TR>		   <TD width="100%">The Value of Filename</TD>	  	</TR>  </TBODY></table></body></html>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...