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.
- There has been a change of paradigm so far as use is concerned. I remember developing lots of
commercial Computer Systems. The need to Train the users was well recognised (even if it was not
always done - at all, or even properly). A rule of thumb was that the time and cost taken over
training users would be about equal to the time and cost of developing the system. That is to say
about 50% of the total.
With the advent of the HTML Browser, the Design and the Human Interface is so different such that the Training Element has been reduced dramatically. You don't believe me !! Well ask the Airlines what proportion of their ticket sales is via the Internet. I have not seen any courses to train folk how to book their tickets on the Internet.
This change of paradigm is G O O D
- There are quite a few different HTML Browsers available for Joe and Jill Public to use.
The sadness is that they all seem to process the HTML Scripts differently.
A script that produces the page you want in one Browser will give a totally different result in another Browser.
This is unfortunate and irritating at least - in general it
is B A D
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.
W3C XML Query
XQuery 1.0: An XML Query Language
Five Practical XQuery Applications
Quilt: an XML Query Language
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.
- First there is something called XSL (Xtensible Style Language) - it is to XML what CSS (Cascading
Style Sheets are to HTML
Some examples are given below.
- The Microsoft company provide an ActiveXObject called MSXML
It can be used in programming languages that run under windows - in particular VBS/ASP (Visual Basic Script/Active Server Pages) - it can also be used in the less well known programming languages.
One that comes to mind, and that I have used it in is dBasePlus
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 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
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.
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)
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.
- The first part gets and loads the XML file
- The second part gets and loads the XSL file
- The third part carries out the Parsing and Transforming the data and then sends the result to the Browser
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
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 result wait for the redirection to occur and then see the Transformation from the XML file appearing in the Left Hand Navigation frame.
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.
It will get better !!
You have been warned !!