B336 title
Murdoch University logo

Laboratory Week 7 - XSL Transformations


Learning Objectives:

  1. Learn how to use XSLT to transform an XML document.

Required Reading:

Lectures: Week 6 lecture 2
Sybex Textbook XML Complete Chapter 12.

Access to Software:

All required software is available in the internal labs. External students may download the required software and install it on your own machine.

In the following exercises, we will transform XML documents with XSLT style sheets using James Clark's XT program. See the downloads page for the link to the XT distribution.The following instructions are for the Windows version of XT. The Unix version operates in similar wayYou can use the Windows or the Unix versions.

XT is not available on gryphon.murdoch.edu.au. Please use your local machine (in the labs or at home) for the following exercises.

Instructions:

  1. Copy all the example XML adn XSL files from the examples directory into your local or network drive. Read the files using a text editor and understand what each of the XSL style sheet does:

    • empty.xsl: an empty style-sheet - uses the default transformation.
    • unit_titles1.xsl: extracting all unit titles.
    • unit_titles2.xsl: extracting all unit titles - a much better example.
    • anotherxml.xsl: transforming to another XML format.
    • tohtml.xsl: transforming to HTML.
    • nodes.xsl: Printing the name of every node in the source tree.

    For each of the XSL style sheets, see the result of the transformation by using the XT program. Do this by typing "xt xml_file xsl_file". Egs.

    C:\TEMP> xt course.xml empty.xsl
    C:\TEMP> xt course.xml tohtml.xsl | more

Exercises:

  1. Write XSLT style sheet that converts course.xml to an HTML document, with the following format:

    <HTML>
    <BODY>
    <H3>Bachelor of Science - Internet Computing</H3>
    <H3>3 years</H3>
    <P>
    The unit B336 Internet Systems Programming is run by: <br> Hiew, Hong Liang (h.hiew@murdoch.edu.au)<br>
    </P>
    <P>
    The unit B108 Introduction to Multimedia and the Internet is run by: <br> Rai, Shri (s.rai@murdoch.edu.au)<br>
    </P>
    </BODY>
    </HTML>
    Don't worry if you do not get the newlines and indentations exactly as above. The important things are the HTML tags and the text within the tags.
  2. Write XSLT style sheet that extracts the unit code (NOT including the unit name) of every unit. Does the structure of the document make it obvious where this piece of information is? Would it be appropriate to change the DTD of course.xml to support this operation? If yes, make the relevant changes and implement a new style sheet?
  3. Write XSLT style sheet that displays the number of units in a course XML file (Hint 1: read the lecture notes on XPath functions, and look up the the available functions in the textbook. The function sum() is NOT the answer).
  4. The following is an example DTD for a new XML application (ie. a new language). It describes pages on a brochure for course information.Write an XSLT style sheet that transform from the course DTD to this new DTD. Try it with the given course.xml document.

    <!DOCTYPE brochure [
    <!ELEMENT brochure (page*)>
    <!ELEMENT page (header?, footer?, courseinfo+)>
    <!ELEMENT header (#PCDATA) >
    <!ELEMENT footer (#PCDATA) >
    <!ELEMENT courseinfo (#PCDATA) >
    ]

Assessable Tasks:

Exercises 1 and 2.

Internal students should demonstrate to your tutor by executing your scripts with your tutor present. This must be done in week 7 or week 8. No marks will be awarded if the work is demonstrated after that - your tutor have no discretionary power on this deadline.

External students should submit the scripts and sample runs as Assignment 3.

 

H.L. Hiew
Unit Coordinator


Document author: H.L. Hiew, Unit Coordinator
Last Modified: Monday, 07-Apr-2003 06:19:48 MST
Disclaimer & Copyright Notice © 2003 Murdoch University
This document is relevant for semester 1, 2003 only