XSLT Laboratory Session

The purpose of this laboratory session is to help you learn about XSLT. To do so, you will be given a source of information in the form of an XML file, and will be asked to use XSLT stylesheets to transform certain parts of the information into HTML. This can be done either by using a standalone XSLT processor, such as Saxon or xt, or by including an appropriate stylesheet processing instruction in the XML file and viewing it using a browser.

The source file contains bibliographic information about papers presented at the ACM Principles of Database Systems (PODS) conference in 1998. Use a browser to view the XML file pods98.xml. Take particular note of the names and structure of the elements in the file, since you will need to know these in order to express the following retrieval requests as XSLT programs. Save a copy of the file pods98.xml (by right-clicking on the link above) in the directory (folder) in which you plan to work.

Below you will be asked to write four stylesheet programs. It is easiest if you write each in a separate file (with the extension (type) .xsl), all in the directory you chose above.

To use Saxon or xt, open a Windows Command Prompt window and change to the directory you chose above. To use xt, type the following in the command prompt window:

n:\xmltools\xt pods98.xml your-xslt-file.xsl output-file.html

where your-xslt-file.xsl is the name of the file you have created containing the particular XSLT stylesheet you want to be applied to the file pods98.xml. The output of the transformation will be written to output-file.html. You can view this file using a browser, or a text editor if you want to see the HTML source produced by the transformation.

To use Saxon instead, type

n:\SaxonHE\saxon pods98.xml your-xslt-file.xsl output-file.html

You may get a warning about using a version 1 stylesheet with a version 2 processor.

You should use a standard text editor, such as Notepad or Textpad, to create the contents of your stylesheet file. A starting skeleton for the file (just the root xsl:stylesheet element) is in skeleton.xsl (right-click to save the file as is).

To use a stylesheet processing instruction in the XML file instead of Saxon or xt, insert

<?xml-stylesheet href="your-xslt-file.xsl" type="text/xsl" ?>

between the XML declaration and the proceedings root element in your copy of pods98.xml. Once again, your-xslt-file.xsl is the name of the file you have created containing the stylesheet you want to apply.

Now write a stylesheet for each of the following. Use one of the methods described above to check that each transforms the XML file as expected:

  1. Write a stylesheet to extract the value of the name element which is a child of the proceedings element in the XML document. The output should be in HTML with the value of the name element being the contents of an h1 heading.
  2. Modify the stylesheet in (1) to extract, in addition, the titles of papers presented at the symposium. Each paper title should be inserted inside double quote marks and should constitute a separate paragraph in the HTML, after the h1 heading.
  3. Write a stylesheet to extract the authors, titles and page numbers of papers presented at the symposium. The output should be in HTML, each paper should constitute a separate paragraph, with the author names listed on one line followed by commas, followed on the next line by the title emphasized and inside double quote marks, followed by a comma and then the characters "pp." (excluding the quotes) and the page numbers followed by a full-stop.
  4. Now modify the stylesheet in (3) so that it produces a list of all the authors' names before the list of papers (where the authors' names also appear). This might be the first step in producing a stylesheet where the list of authors provides a hyperlinked index to authors' papers. Each author's name should be on a separate line. Do not worry about trying to remove duplicate names.