BizTalk Utilities CV ,   Jobs ,   Code library  
 
 
Page 4 of 4 Previous Page Table Of Contents
Table of Contents

The Test Page

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.

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:

q Button 1 shows the original un-translated source document (incoming.xml)
q Button 2 shows the dynamically-generated XSL returned as a result from interpreter.asp
q 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.

So now we have finished our discussion on styling XML for our web browsers. We will use XSL frequently as we progress through this book. In the next chapter we shall move on to storing and retrieving XML data from databases using ActiveX Data Objects (ADO).

1999 Wrox Press Limited, US and UK.

Page 4 of 4 Previous Page Table Of Contents
 

Recent Jobs

Integration Specialist Needed - Wor
Virtualization Server Infrastructur
A great opportunity to Digital Vide
here is a greate opportunity as a S
A great opportunity as a Network En

View all Jobs (Add yours)
View all CV (Add yours)




swimming pool contractor
chicago web site design
conference calling
Domain Names
online fax service
Diesel sunglasses
answering service


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP