Universiteit Leiden

XSLT Exercises

The files that are mentioned in the exercises below can all be found in the folder "XSLT.zip". Download this zipped folder, and unzip/unpack it in your working directory.

Exercise 1

Write a stylesheet that can transform the XML file named "letter.xml" into an HTML document containing the following information:

Letter from De Erven F. Bohn to W. Blackwood and sons

Dear Sirs!

We beg to apply to you the kind request for sending us one week before the publication one copy of Bulwer's novel: Kenelm Chillingly, His adventures and opinions, which book you have in the press, for what we are inclined to pay 30£. When it were possible to send us already now the first volume by the post; it would be yet more agreeable. Mr H.A. Kramers at Rotterdam readily will be our pledge.

 

yours truly

De Erven F. Bohn


Note that you don't necessarily need to replicate the font colours or the background colour exactly. The main aim of this exercise is to the extract the necessary information from the XML source file and to copy it into the HTML file that results from the transformation. Follow the steps below.

<html>
  <head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" />  
         
  <title><!-- title from head --></title>
 </head>  
<body>

  <h2><!-- title from head --></h2>  
   <p> <!-- Opening salute from body/greeting --></p>  
  <p><!-- Body of the letter from body/p --></p>  

   <p><!-- Closing salute from body/salute --></p>    
 <p align="center"><!-- Name of the letter's sender from body/signed--></p>  

</body>
</html>


Exercise 2

Create a stylesheet that can transform "bibliography.xml" (from the folder you have downloaded) into an HTML document that looks as follows:

A Social History of the Media, from Gutenberg to the Internet
The printing revolution in early modern Europe
The kiss of Lamourette : reflections in cultural history
Buchkunde: ein Überblick über die Geschichte des Buches
Books in the digital age : the transformation of academic and higher education publishing in Britain and the United States
Die literarische Welt des Mittelalters
l' Apparition du livre
Les métamorphoses du livre : entretiens avec Jean-Marc Chatelain et Christian Jacob

Follow the same steps as in exercise 1:


<html>
<header>
<title>
Bibliography
</title>
</header>
<body>

<p>
<!--
Display the full title of EACH item. The title must be 
followed by a line break ('<br/ >')
-->
</p>

</body>

</html>

Exercise 3

Using the result of exercise 2, create a stylesheet that can display all the book titles in "bibliography.xml" in alphabetical order.

To do this, make use of the <xsl:sort> element, as explained in section 8 of the XSLT tutorial. This element must be the first element within the body of the <xsl:for-each> element.

Exercise 4

Building on the stylesheet that you have created for exercise 3, create a stylesheet that can transform "bibliography.xml" into an HTML file which presents all the titles in the following citation style:
[Full name of the author (inverted order)], [Title (in italics)]. [Place]: [Publisher], [Year].
Sort the list by the last name of the author. Add all the punctuation in <xsl:text> elements.

The result should look as follows:

Brinker-von der Heyde, Claudia. Die literarische Welt des Mittelalters. Darmstadt: Wissenschaftliche Buchgesellschaft, 2007.
Burke, Peter. A Social History of the Media, from Gutenberg to the Internet. London: Polity Press, 2005.
Darnton, Robert. The kiss of Lamourette : reflections in cultural history. New York: Norton, 1990.
Eisenstein, Elizabeth Lewisohn. The printing revolution in early modern Europe. Cambridge University Press, 1983.
Febvre, Lucien. l'Apparition du livre. Paris: É́ditions Albin Michel, 1971.
Funke, Fritz. Buchkunde :ein Überblick über die Geschichte des Buches. München: Saur, 1992.
Martin, Henri-Jean. Les métamorphoses du livre : entretiens avec Jean-Marc Chatelain et Christian Jacob. Paris: Albin Michel, 2004.
Thompson, John B. Books in the digital age: the transformation of academic and higher education publishing in Britain and the United States. Cambridge: Polity, 2005.

Exercise 5

Write a stylesheet that can filter the titles in "bibliography.xml". Firstly, create a bibliography containing only the English titles. Secondly, create a bibliography listing the titles written after the year 2000. Obviously, you can re-use (parts of) the code that you have created for exercise 4.

Use the HTML code below as a basis.

<html>
<header>
<title>
Bibliography
</title>
</header>
<body>

<h2>English titles</h2>

<p>
<!--
Display the titles, followed by a line break.
-->
</p>

<h2>Titles written after 2000. s</h2>

<p>
<!--
Display the titles, followed by a line break.
-->
</p>

</body>
</html>

This HTML result can be created using a stylesheet containing only one <xsl:template>. With this organisation of the XSLT file, you will probably need to repeat some code. You can make the code in the stylesheet more efficient by working with multiple templates. You could create a separate stylesheet for the <item> element and involke this second template using <xsl:apply-templates>, as explained in the last two sections of the XSLT tutorial. OPTIONALLY, you can try to develop such a stylesheet containing two templates.

Exercise 6

Create an XSLT stylesheet that can transform the XML file named "collection.xml" into a web page (i.e. an HTML file) that presents the information about the letters as follows:

Letter Collection of the University of Leiden

  • Letter from Antheunis-Conscience to Sijthoff, Albertus Willem
  • Letter from Behrend, Fritz to Vreese, Willem Lodewijk de
  • Letter from Blackwood, William to Tiele, Cornelis Petrus
  • Letter from Butz, Kilian to Kraus, Fritz Rudolf
  • Letter from De Erven F. Bohn to William Blackwood & Sons
  • Letter from De Erven F. Bohn to Lytton, Lord
  • Letter from De Erven F. Bohn, to Sampson Low, Marston and Company, London
  • Letter from Fuhri, Koenraad to Kruseman, Arie Cornelis
  • Letter from Gamillscheg, Ernst to Huizinga, Johan
  • Letter from Hamel, J.A. van to Sijthoff, Albertus Willem
  • Letter from Harting, P. to Muller, Jacob Wijbrand
  • Letter from Hawkshaw, John to Tideman, Jan
  • Letter from Laufer, Berthold to Schmeltz, Johannes Diederich Eduard
  • Letter from Muller, Frederik to Tideman, Jan
  • Letter from Muller, Frederik to Sijthoff, Albertus Willem
  • Letter from Muller, Frederik to Sijthoff, Albertus Willem
  • Letter from Schneider, Lina to Tiele, Cornelis Petrus
  • Letter from Sijthoff, Albertus Willem to Hensbroek, Pieter Andreas Martin Boele van
  • Letter from Suringar, Gerard Tjaard Nicolaas to Kruseman, Arie Cornelis
  • Letter from Wirth, Herman Felix to De Erven F. Bohn

 

Exercise 7

Building on the code that you created for exercise 7, create an XSLT stylesheet which only displays the letters in the file "collection.xml" written before 1900.
Add the criterion in square brackets after the element mentioned in the <xsl:for-each> element.

Exercise 8

Building on the code that you created for exercise 6, create an XSLT stylesheet that displays quantitative information about the file "collection.xml". The web page that is created should display the following information:

These number should not be typed in manually; they must be calculated by the stylesheet.

Exercise 9

The stylesheet "tei-html.xsl" (in the zipped folder you've previously downloaded) can transform the descriptive markup in the TEI document to HTML elements that specify the typographic appearance. Read this XSLT stylesheet and try to determine which rules are given for the following TEI elements:

  1. <gap>
  2. <supplied>
  3. <pb>
  4. <lb>
  5. <title>
  6. <hi rend="underlined">