| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

CD Catalog Example Code

Page history last edited by Dr. Ron Eaglin 9 years, 7 months ago

This code is meant to accompany the lecture - Lecture - XML - Displaying and XML Page with XSL 

 

The code puts comments on each line to better understand the code and also removes support for earlier versions of Internet Explorer.

 

Note - this will work native in FireFox, you must let FireFox access local files to test locally.

Chrome - to allow Chrome to access local files for testing you must run Chrome with the switch --allow-file-access-from-files

IE9 - Add <meta http-equiv="X-UA-Compatible" content="IE9" /> to header to force compatibility.

 

CDCatalog.html

------------------------------------------------------------------------

<!DOCTYPE html5>
<html>
<head>
<script>
function loadXMLDoc(dname)
{
// This function will open an XML document and return it
// To do this we must create XMLHttpRequest object to get the file
// from the server
  xhttp=new XMLHttpRequest(); 

// Using GET protocol we open a connection and give it the file name  
// The false is whether the request is Synchronous or Asynchronous
// Default is Asynchronous - we want synchronous - thus argument false is sent
  xhttp.open("GET",dname,false);    
  
  // This sends the request on Chrome - you must set browser to allow access from files
  // to use on local machine (OK on server) 
  xhttp.send("");
  
// The Object returned is of type XMLDocument
  return xhttp.responseXML;
}
function displayResult(fname)
{
  // Gets the XML Document and puts in xml
  xml=loadXMLDoc(fname+".xml");
  // Gets the XSL Document and puts in xsl
  xsl=loadXMLDoc(fname+".xsl");
  
  // Creates and XSLT Processors using the xsl
  xsltProcessor=new XSLTProcessor();
  xsltProcessor.importStylesheet(xsl);
  
  // Formats the xml document using the XSL
  resultDocument = xsltProcessor.transformToFragment(xml,document);
  
  // Puts the results into the div tag example
  document.getElementById("example").appendChild(resultDocument);
}
</script>
</head>

<body onload="displayResult('cdcatalog')">
<div id="example" />
</body>
</html> 

Comments (0)

You don't have permission to comment on this page.