Java-Informations-Tage 1999 – Die wissenschaftliche GI / ITG Fachtagung zum Thema JAVA

# About the XML in jit.xml

Since a conference program makes a nice appearence in XML, and Microsoft IE5.0 is rumored to “speak” XML, I took the opportunity to experiment a little bit with the features of XML. The task (as You can see) was to create an online program for the JIT'99 conference on Java. Of course, this program was to be generated from a kind of database I created in the first place, and of course too, I hate typing.

It is obviously straightforward to traverse a tree and create a structured document of the form:

    <program>
      <day>
        <track>
          <session>
            <talk>
              <title>
                Invited talk: Swinging on the ...
              </title>
              <author>
                <name>
                  Erich Gamma
                </name>
              </author>
            </talk>
          </session>
        </track>
      </day>
    </program>

And this is exactly what the content of jit.xml looks like! Fine. The hard part was to write a stylesheet to make the document look like I wanted it to look like. I tried CSS and found it easy to use and limited in usefulness. CSS forces You to create the XML document with a layout in mind – excatly what I had not done in the first place.

So I learned XSL, the extensible stylesheet language – although I could not detect any extensibility in it... While I found Microsoft's implementation a little bit restricting since it is mapping everything to HTML in the end, it is still a very powerful way of doing things. In the end, I was happy with jit-xsl.xml and I found it frustrating that I had to generate HTML documents at all.

To give You an idea what XSL is about, I'll say the following (read the spec for more): It is three files in one:

1. A script file to process the data

2. A Cascading stylesheet (CSS) file

3. An HTML template file (actually, a directory full of those)

As a script file, it resembles shell script languages rather than javascript or such. It has instructions like `tcsh`'s foreach, and if but also pattern matching capabilities. The foreach is able to iterate over the tree in the XML file (if the latter was generated by a foreach in some shell script iterating over some file system tree, both foreachs actually are isomorphic :-)

Just like CSS, XSL files may contain style sheet statements. XSL defines its own style sheet language Microsoft chose to ignore. So, traditional CSS embedded into an `<html:head>`-tag must be used instead.

As a directory of HTML template files it holds fragments of HTML source code which are filled with data. While processing the XML file the XSL processor (IE5.0) creates an internal HTML file from these fragments which is then displayed eventually. I found this a very convenient way of doing things.

You now may find it useful to have a look at my jit.xsl stylesheet (You may load it into IE5.0 which displays it as an XML document tree :-)

This way XSL provides an elegant way to separate content and layout even in HTML documents – the prerequisite in maintaining larger sites. Of course, this requires a way of producing HTML from the XML data!

Since nobody wanted to tell me how to output the HTML tree IE5.0 already created internally, I found out myself. Here is how You can use MS IE5.0 to convert XML to HTML (the Microsoft website somehow makes You believe that You need Active Server Pages (ASP) for this...):

(1) create a file "xml2html.html" containing the following content:

    <html><head>
    <!-- MS IE5.0 only -->
    <script language="jscript">
      function xml2html () {
        var sourceFile = "jit-xsl.xml";          // the XML document
        var styleFile = "../../styles/jit.xsl";  // the XSL stylesheet
        //    Load the document and stylesheet:
        var source = new ActiveXObject ("Microsoft.XMLDOM");
        source.async = false;
        source.load (sourceFile);
        var style = new ActiveXObject ("Microsoft.XMLDOM");
        style.async = false;
        style.load (styleFile);
        //    convert into HTML:
        document.close (); document.open ();
        document.write (source.transformNode (style.documentElement));
        alert ("You may now use 'View/Sourcecode'\n"
            + "to retrieve the generated HTML code and,\n"
            + "when in editor You may use 'File/SaveAs'\n"
            + "to store the generated HTML code.");
      }
    </script></head>
    <body onLoad="javascript:xml2html()"></body></html>

(2) load this file into MS IE5.0 (i.e. doubleclick the file) and follow the instructions in the alert-box. Note that the above file is generic if You inquire about `'sourceFile'` and `'styleFile'` parameters from within the JavaScript!

I found it kind of magic to load one HTML-file, and save another ;-)

Hope You found these bits worth to read,

Falk Langhammer

[ XML source | XML XSL-formatted | XML CSS-formatted | XSL stylesheet | CSS stylesheet | HTML conversion script | HTML converted from XML | about XML description ]

|  | Programmübersicht Liste aller Vorträge XML Tutorium Zielgruppe Für die Sprecher DJEK-Vorträge Ausstellung |
Programm...
Willkommen & Anmeldung...
Aktuelles...
Organisation...
Archiv...