Monthly Archives: February 2013

XML and XSLT

Several possibilities exist to read XML files. One such possibility is to have it read via XSLT. This procedure is composed of three elements:

  • The XML file that is to be read;
  • A XSLT file that provides us with instructions on how to handle the XML file.
  • An engine that translates the XML file via the instructions as given in the XSLT file into something that is readable.

XMLXSLT

 

An example may clarify this. Suppose, we have a XML file that starts with these lines:
XML

 

For a full XML file see here. Within this XML file, it is indicated that an XSLT file “cdcatalog.xsl” is to used as a file that contains instructions on how to read this XML file. In this case, the set of instructions looks like: XSLT.
If the XML file is then accessed with a programme that contains an engine to apply the instructions as contained in the XSLT, we get the desired result. Every modern web browser contains such engine. Hence if the web browser is used to read the XML file, we already have the desired result. This is how I could see the XML file when I read this with my webbrowser:

 

HTML

Some Javascript to read XML

javascript1
I know that lots and lots of possibilities exist whereby an XML file can be read. One set of possibilities is to use a Javascript. One then stores a script on the webserver that is processed by the web-browser. Upon processing, the XML file in read and can be stored in another format. A quick query provided me with three such scripts where an XML file is read and subsequently presented in an HTML file.
Below, I have included a link where three scripts are executed.

click here

If the reader would like to see the scripts, he could look at the source that can be read from the web browser itself. After all, the script must be read by the web browser as to execute it in the browser.
It is also nice to see that the scripts are interpreted differently by different web browser. The Internet Explorer will give another result as, say, the Chrome browser. This shows that the scripts are interpreted by the web browser and we have the consequences of different web browser and ensuing different results.