CS 371, Fall 2001
Lab 9, Part 2: DTD's and XSLT

The goal of this lab is to write a DTD for a simple XML document format, and to produce a valid document based on that format. A second, extra-credit exercise involves writing an XSLT stylesheet for transforming documents that use your DTD into HTML.

This lab is due, along with Part 1 of the lab, in class on Wednesday, December 5. You should turn in the following:

If you choose to do the second, optional part of the lab for extra credit, you should also turn in:

Part 1 of the lab (from November 16) is worth 15 points. The first exercise in Part 2 (today's lab) is worth 10 points. The second exercise in Part 2 is worth an additional 10 points of extra credit.


Exercise 1: Writing a DTD

For this part of the lab, you should start with the XML document that you wrote for Part 1 of the lab. You should add a DTD to the XML document so that it becomes valid rather than merely well-formed.

I suggest that you use an internal DTD, like the one in the sample document that I handed out in class. (To see that document on-line, click here.) Nevertheless, the DTD that you write should describe an entire, general class of documents, not just your sample document. For example, if your sample document is an address book, then the DTD should describe a general format for address books, and the sample document should be just one example of such an address book.

After adding the DTD to your document, you might want to test whether the document is still well-formed by loading it into Mozilla. Mozilla will report any basic syntax errors. However, Mozilla will not check whether the document is valid. The document that you submit for this exercise is required to be valid. There are two ways to check its validity:



Exercise 2: Using XSLT

This part of the lab is optional and will be counted for extra credit if you do it.

For this part of the lab, you should write an XSLT stylesheet and use it to transform your XML document into an HTML document (with a reasonable format). Your stylesheet should work for any XML document that is valid according to your DTD. In class, we looked at a sample XSLT stylesheet, schedule.xsl, that transformed schedule.xml into the HTML document schedule.html. For an alternative style sheet for the same XML file, you can look at schedule-2.xsl. The HTML output can be found in schedule-2.html. (There are copies of all these files in /home/cs371.)

To apply an XSLT transformation to an XML document, you have to run a program. On the cslab machines, you can use the command xml_transform. (This is another alias for a Java program from the Xalan project.) The syntax for using this command is:

     xml_transform -IN input_file -OUT output_file -XSL xsl_file

or for a specific example,

     xml_transform -IN schedule.xml -OUT schedule.html -XSL schedule.xsl

(Note that there is no reason for all these files to be named schedule.something. The names can be anything.)

You should apply this command using your own XML file and XSLT file.


David Eck, 30 November 2001