HOME  |    TRAINING  |   FREE TUTORIALS   |   JOBS
Find out more about our new RSS feed.
FREE Tutorial
PROFESSIONAL ASP XML : CASE STUDY DATA DRIVEN XSL PART 4 - THE TEST PAGE

CATEGORY
SEARCH OUR OTHER TUTORIALS

DESCRIPTION

Now let's see this all at work by looking at the test page, which is included in the source download as default.asp. We will use the JavaScript alert() function to display the XML because if we show it in the browser the tags will not be visible.


This free tutorial is a sample from the book Professional ASP XML.


When it loads, the test page will invoke the init() function. It will create two instances of the XML DOM, one for the XML source document, and the second for the dynamic XSL file. The last thing it does is apply the XSL to the source XML, and saves the resulting string in the "processed" variable. This is our translated XML. The full code is shown here:

<html>
<head>
 <link REL="stylesheet" TYPE="text/css" HREF="list.css">
</head>
<body>
<hr color=red>

<button onclick='alert(source.xml);'>1. Show incoming.xml</button>
<button onclick='alert(dynstyle.xml);'>2. Show dynstyle.xsl</button>
<button onclick='alert(processed);' id=button1 name=button1>
 3. Show Translation
</button><br>
<hr color=red>
<script FOR="window" EVENT="onload">
init();
</script> 

<script>
var source;
var sourceName = "incoming.xml";
var dynstyle;
var dynstyleName = "interpreter.asp";
var processed = "";

function init(){
 // Do init stuff. Called by the parent frame.
 source = new ActiveXObject('Microsoft.XMLDOM');
 source.async = false;
 source.load(sourceName);   
 // did the XML file load OK?
 if (source.parseError.errorCode != 0){
   msg = 'Error loading SOURCE file.' 
   msg += '\nDescription: ' + source.parseError.reason  
   msg += '\nSource text: ' + source.parseError.srcText
 }
 root = source.documentElement;

 dynstyle = new ActiveXObject('Microsoft.XMLDOM');
 dynstyle.async = false;
 dynstyle.load(dynstyleName)
 // did the XML file load OK?
 if (dynstyle.parseError.errorCode != 0){
   msg = 'Error loading DYNSTYLE file.' 
   msg += '\nDescription: ' + dynstyle.parseError.reason  
   msg += '\nSource text: ' + dynstyle.parseError.srcText
 }
 processed = source.transformNode(dynstyle)
}
</script>
</body>
</html>

I have provided three buttons on the test page that show the three entities that make up this example:

  • Button 1 shows the original un-translated source document (incoming.xml)
  • Button 2 shows the dynamically-generated XSL returned as a result from interpreter.asp
  • Button 3 shows the translated version of the source document, after the style has been applied to it.

How it Works

The following screen shot shows the un-translated source document:

This screen shot shows our dynamically generated XSL:

This final screen shot shows the result of the translation:

Summary

In this chapter, we have seen a way to use ASP to generate an XSL file dynamically. We did this by using an ASP page to create an instance of the XML DOM and employing DOM methods to build the result tree. The information needed to build the result tree came from the contents of an XML file. A test web page then used the dynamic XSL to translate from one XML structure to another.




5 RELATED COURSES AVAILABLE
HTML 4.0 INTRODUCTION
To create, format and publish a small website using HTML 4.0. You will learn to create web pages incorporating fo....
MICROSOFT INTERNET EXPLORER 6.0 INTERNET INTRODUCTION
This course provides readers with an introduction to the concept of the Internet and the opportunity to gain a br....
A+ MODULE 5 - THE INTERNET
At the end of this course you will be able to: describe the functions of an operating system, describe the featur....
JAVASCRIPT PROGRAMMING
This training course aims to teach the reader the fundamentals of JavaScript. This course covers topics such as -....
I-NET+ MODULE 8 - DEVELOPING A WEB SITE
On completion of this module, readers will be able to: create HTML pages incorporating different document-, parag....
 
0 RELATED JOBS AVAILABLE
CONTACT US
Friday 21st November 2008  © COPYRIGHT 2008 - VISUALSOFT