I said many years ago that I believed the the HTML Browser would become the Graphical User Interface of choice. It seems to me that the prediction is coming true.

You might be curious why I mention it here and what it has to do with a warning about XSL. Well I will keep you waiting for a while before your curiosity is satisfied. There are two very pertinent points that need to be made about the onset of HTML Browsers.


My current prediction is that XML technology is the Structured Database of the future. Indeed if I were a supplier of Databases or Database Management Software, I would either be changing direction to embrace XML or being very concerned about the future.


First then let me show you a TXT file Click here to see one

Next let me show you an XML file containing exactly the same characters Click here to see it (names1.xml)

You will see that Internet Explorer knows about XML files. It checks that the file is 'Well Formed' - if not, it will tell you so and show you where in the file the error is. If it is 'Well Formed', it will show the contents, they will be coloured to aid the readability.

This is possible because Internet Explorer contains something called an XML Parser.

Now I will show you an XML file containing exactly the same data Click here to see it (names2.xml)

I have just checked three (otherwise respectable) of the many books that I have that give information on XML files that give examples similar to the to the previous two files that I have just shown you. All of them say the two files are the same.
That is manifest nonsense, they do not even have the same number of characters !

It is correct to say that the two files contain the same information (or data).

For your information the first one (names1.xml) is said to hold the data as Attributes

The second one (names2.xml) is said to hold the data as Elements

It is important that you recognise the differences because you would need to use different Program Code or Script to process (or use) the information to get the same results out of the two different representations of the data.

If we accept the generally accepted current philosophies that 'the low cost of storage media (disc space) is so inexpensive, that the size of files is not worthy of concern' then we could consider the two files as functionally the same. Then we need to decide which file organisation we wish to use. The main criteria used in making that decision is how we intend to process the data. More about that later !

Now just to muddy the water even further, I will show you another file that holds the data as both Attributes and Elements. Click here to see it (names3.xml)

& finally, let me show you that you can throw in other data Elements at will. Click here to see it (names4.xml)

If you look at the two person records that have phone numbers, you will notice that the sequence of the Elements differs - and believe me XML file processing tools will not have any problems with that. Similarly the sequence of Attributes is also inconsequential.

You will also see that it is allowed to have Elements in some records and not in others (in other words, empty Elements are not needed.

All in all, XML files are a flexible and easy to read method of storing information (or data).


Now, let us consider the processing of the data held in XML files. You will realise of course, that you could write in any programming language of your choice and treat the files as ordinary common-or-garden text files - BUT - that would really be a 'hard work' way of doing it !!

All respectable databases can be explored using something called SQL (Structured Query Language). Well, at the time of writing this, I can find no trace of any product giving SQL access to data held in XML files - BUT - W3C, the World Wide Web Consortiun is on the case. It has/is preparing a specification for something called XML Query. Again, at the time of writing, I can find no product that processes queries written as XML Queries - but soon !!! Below, there are some links that may be of interest to you.

XML Query Links
W3C XML Query
XQuery 1.0: An XML Query Language
Five Practical XQuery Applications
Quilt: an XML Query Language
Quilt Parser

But in the meantime, there are a couple of things that can be used to help one to manipulate the data held in XML files.



XSL

Xtensible Style Language

First then let me show you a new XML file Click here to see one (cd_catalog.xml)

Next, let me tell you that XSL files are written as XML files. Now let me show you one that can be used to process the XML file that you have just seen. Click here to see one (cd_catalog.xsl)

How can you use the XSL style sheet to process the XML data - well you will remember that the XML file started thus:-




<?xml version="1.0" encoding="ISO8859-1" ?>
<CATALOG>
  <CD>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
. . . . . etc


		

To make the XML file use the XSL instructions, add a second line in the XML file as thus:-




<?xml version="1.0" encoding="ISO8859-1" ?>
<?xml-stylesheet type="text/xsl" href="cd_catalog.xsl"?>
<CATALOG>
  <CD>
    <TITLE>Empire Burlesque</TITLE>
    <ARTIST>Bob Dylan</ARTIST>
    <COUNTRY>USA</COUNTRY>
    <COMPANY>Columbia</COMPANY>
. . . . . etc


		

I have saved the new XML file as cd_catalog_withXSL.xml Click on it and see what happens.
NOTE - On this occasion, there is no seperate HTM file - the output is produced by the XSL specification being used on the XML data.

It is also possible to use 'IF' and 'MATCH' statements in XSL files.
Click here to see one (cd_catalog_if.xsl)
Click here to see the effect (cd_catalog_if_withXSL.xml)

You may want to have a look at XSL Introduction by Jan Egil Refsnes - it certainly helped me mightily - thank you Jan !!

Look at each of the pages at the top of the Table of Contents on the Left Hand Side of the page - you will learn something from each of them !!

You might now care to look at how it is possible to incoporate XML and XSL files into HTML files.

Click here to see test10122000.xml

Click here to see test10122000.xsl

Click here to see how test10122000.htm works
If you want to see the HTML Script, when you get the page up, Click on 'View' and then 'Source'

The mind blowing functionality can be seen if you click on the Column Titles once and then again for each of the columns it turn. That is so sweet and, if you look at the code, so simple !!

It is very simple to use these three files as skeletons for your own data and display it
BUT
beware about the sortability of Date and Number columns - the sorting in here is on Characters shown in the fields. (this is resolvable but is to involved for this page - maybe I will show you an example later on another page)

Confession time - I have to tell you that this is not pure XML+XSL. It does make use of the embeded ActiveXObject in Internet Explorer. The next part of the page looks at ActiveXObjects a bit more.



MSXML

an ActiveXObject

We will start by looking at an example provided by Microsoft. It uses three files. It is a very sophisticated example that I am showing you to start with - this is in order to give you an enthusiasm to look at the simpler example that follows.

Number one is an XML file Click here to see it (books.xml)

Number two is an XSL file Click here to see it (CatalogFilter.xsl)

Number three is an ASP file. That is an Active Server Page - ASP pages are usually written in VBS (Visual Basic Script) - this is unusual in that it is written in JavaScript. This constrains the server to be running Microsoft IIS. The contents are shown below:-





<%@LANGUAGE="JavaScript"%>
<%Response.expires=-1;
// catalog.asp
// Sorts books from a given catalog by title, for a given Genre.
function loadSource(sourceName){
    var xmlDoc=new ActiveXObject("MSXML2.FreeThreadedDOMDocument.4.0");
    xmlDoc.async=false;
    xmlDoc.load(Server.mapPath(sourceName));
    return xmlDoc;
    }

function getProcessor(transformName){
    if ("" + Session(transformName) == "undefined"){
        var xslDoc=new ActiveXObject("MSXML2.FreeThreadedDOMDocument.4.0");
        var xslTemplate=new ActiveXObject("MSXML2.XSLTemplate.4.0");
        xslDoc.async=false;
        xslDoc.load(Server.mapPath(transformName));
        xslTemplate.stylesheet=xslDoc;
        xslProcessor=xslTemplate.createProcessor();
        Session(transformName)=xslProcessor;
        }
    else {
        xslProcessor=Session(transformName);
        }
    return xslProcessor;
    }

function transformData(srcDoc,processor){
    processor.input=srcDoc;
    processor.output=Response;
    processor.transform();
    return true;
    }

function main(){
    var srcDoc=loadSource("books.xml");
    var processor=getProcessor("catalogFilter.xsl");

    var genre=Request("genre");
    if(""+genre=="undefined"){
        genre="all";
        }
    else {
        genre=""+genre;
        }           
    processor.addParameter("selected_genre",genre);
    transformData(srcDoc,processor);
    }    

main();    
 %>



		

Click here to see it (Catalog.asp)

Now let us go back to the simple and generic way of using the MSXML Object on the server. This technique users an XML and XSL file mentioned and shown earlier in this page.

By using this technique, the browser on the Client can be anything - it does not need an XML Parser because the ASP file causes all the work to be done on the Server which then delivers simple HTML script to the Browser. The fact that we are using an ASP file constrains the server to be running Microsoft IIS. The contents are shown below:-





<%
'Load the XML
set xml = Server.CreateObject("Microsoft.XMLDOM")
xml.async = false
xml.load(Server.MapPath("cd_catalog.xml"))

'Load the XSL
set xsl = Server.CreateObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load(Server.MapPath("cd_catalog.xsl"))

Response.Write(xml.transformNode(xsl))
   
 %>



		

You will see that there are three parts to this file.

You can simply change the file names in the first and second part to process your own data.

Click here to see it (cd_catalog_tests.asp)

A final example of processing for this page will simply show you the XML file used and its results on a real life web page.

If you want a copy of the ASP file that does the transformation, please ask and I will EMail you a copy.

The XML file is 'well formed' but to my eternal shame very scruffy and dirty
BUT
it is simple to change and as it is used dynamically, the Web Page changes the next time it is loaded.

Click here to see the XML file

Click here to see the result wait for the redirection to occur and then see the Transformation from the XML file appearing in the Left Hand Navigation frame.



XSL WARNING

Parsers differ

In the same way as Browsers differ, so do Parsers. The Parser used in Internet Explorer differs from the Parser used in the MSXML Object and other Parsers differ from both of them.

Part of my reason for writing this page is because I used some XSL code from a very well respected book on XSL and spent many days of effort trying to get it to work. Eventually I wrote to the Technical Editor for the book who eventually replied that the code had been tested on a Parser that I did not possess and that it had not been tested on Internet Explorer and worse still did not work in Internet Explorer.
BUT
It will get better !!

You have been warned !!