XSLT Exercises

To do these exercises, you need to download a number of sample XML files. They have been placed in this folder (from which you also downloaded the XSLTs used for the Transformation of XML).

Exercise 1

Follow the steps specified in the list below to create a stylesheet that can transform letter.xml into an HTML document that looks as follows:

Letter from De Erven F. Bohn to W. Blackwood and sons, January 22nd, 1873

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
  • From the folder that you have downloaded, open the file “letter.xml” in Oxygen. Choose File > New in Oxygen and select ‘XSL stylesheet’. Save the new file as “letter.xsl” in the same directory as the XML file.
  • Build the style sheet. The HTML codes that you need to use in your XSLT stylesheet for this exercise are provided below. Add XSLT-code on the positions of the comments.

Note that XSLT transforms the structure of an XML source file into a result file of many types. You will have to insert the structural code of the result file yourself: if you want to create an HTML file from an XML file with XSLT, this implies that you will have to add the fundamental elements of the HTML-result file.

<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/p --></p>
     <p align="center"><!-- Name of the letter's sender from body/signed--></p>
  </body>
 </html>

Exercise 2

Create a stylesheet that can transform “literatureList.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

Exercise 3

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

Exercise 4

Building on the stylesheet that you have created for exercise 3, create a stylesheet that can transform “literatureList.xml” into an HTML file as below.
Note that it displays the full name of the author (inverted order), the title and the full imprint (in the form Place: Publisher, Year). Sort the list by the last name of the author.

  • 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 four separate stylesheets (1-4) that can make the bulleted listst with the following selections from “literatureList.xml”. You should write separate stylesheets for these four subquestions. Note that it might be wise to re-use (parts of) the stylesheet you have built for Exercise 4.

  1. Only the English titles
  2. Titles written after the year 2000.
  3. The titles that are NOT written in French.
  4. The titles published in New York.

 

Exercise 6

Create a stylesheet that can transform “poem.xml” (from the folder you have downloaded) into an HTML document that is presented looks as follows:

Snow

The room was suddenly rich and the great bay-window was
Spawning snow and pink roses against it
Soundlessly collateral and incompatible:
World is suddener than we fancy it.

World is crazier and more of it than we think,
Incorrigibly plural. I peel and portion
A tangerine and spit the pips and feel
The drunkenness of things being various.

And the fire flames with a bubbling sound for world
Is more spiteful and gay than one supposes –
On the tongue on the eyes on the ears in the palms of one’s hands –
There is more than glass between the snow and the huge roses.

 

Exercise 7

Download and open the file “wilde-windermere.xml“. This contains the full text of the play Lady Windermere’s Fan by Oscar Wilde, in TEI-markup. Write a stylesheet which can make the following selections in the play:

  1. All parts spoken by Lord Darlington;
  2. Parts in which Lord Windermere speaks of Mrs Erlynne;
    N.B. use contains( element , ‘text’ ). Also note that you can COMBINE two different conditions using the keyword ‘and’ , as follows: condition1 and condition2
  3. Stage directions indicating the entrance of a character on the stage;
  4. Parts spoken by Lady Windermere which consist of less than 50 characters. To test string-length. N.B. use string-length(p) &lt; 50 

For questions 1, 2 and 3, you can use the code below as a basis. In this code, you only need to add the appropriate XPath expressions in for-each and in value-of.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 version="1.0">
 <xsl:template match="TEI">
 <html>
 
 <body>
 <p>
 
 <h3><!-- Description of the list--></h3>
 <ul>
 
 <!-- 
 <xsl:for-each select="">
 <li>
 <xsl:value-of select="" />
 </li>
 </xsl:for-each> -->
 
 </ul>
 
 
 </p>
 </body>
 </html>
 </xsl:template>
 
</xsl:stylesheet>

Xpath can also be used to produce quantitative information about an XML file. The count() function is very useful for this purpose. Write an XSLT stylesheet which can produce data about the following aspects of the TEI file.

  1. The number of parts spoken by Lady Windermere
  2. The number of parts spoken by Lady Windermere in the first act

Use the code below as a basis.

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 version="1.0">
 <xsl:template match="TEI">
 <html>
 
 <body> 
 <p>

<h3>The number of parts spoken by Lady Windermere:</h3>
 <xsl:value-of select=""/>

<h3>The number of parts spoken by Lady Windermere in the first act</h3>
 <xsl:value-of select=""/>
 </p>
 </body>
 </html>
 </xsl:template>
 
</xsl:stylesheet>

Note that you do not have to build full XSLT stylesheets (you still can do so, of course). Oxygen provides an XPath engine in which you can test your XPath expressions. You can do this exercise by firstly writing down the expression in a text file. The complete Path expression can then be copied and pasted into the XPath engine in Oxygen.

Exercise 8

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\”>

Exercise 9

Create an XSLT that can transform the file “collection.xml” into the HTML document below:

 

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 10

Create a single XSLT stylesheet  that displays quantitative information about the file “collection.xml”:

  • The total number of letters in the collection.
  • The number of letters written before 1900.
  • The number of letters in English.

Also modify the list that you have created for exercise 9. Display only the shelfmarks of the letters which are addressed to A.W. Sijthoff.