Exercise 1.
- The root of the XML file is <TEI>
- The direct children of <text> are <front> and <body>.
Exercise 2.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="collection">
<html>
<head></head>
<body>
<h2 align="center">
<xsl:value-of select="head"/>
</h2>
<p>
<xsl:text>From </xsl:text>
<xsl:value-of select="body/letter/author" />
<xsl:text> to </xsl:text>
<xsl:value-of select="body/letter/recipient" /><br/>
<xsl:value-of select="body/letter/place"/><br/>
<i>
<xsl:value-of select="body/letter/callnumber"/>
</i>
</p>
</body>
</html>
</xsl:template>
<head></head>
<body>
<h2 align="center">
<xsl:value-of select="head"/>
</h2>
<p>
<xsl:text>From </xsl:text>
<xsl:value-of select="body/letter/author" />
<xsl:text> to </xsl:text>
<xsl:value-of select="body/letter/recipient" /><br/>
<xsl:value-of select="body/letter/place"/><br/>
<i>
<xsl:value-of select="body/letter/callnumber"/>
</i>
</p>
</body>
</html>
</xsl:template>
Exercise 3.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="collection">
<html>
<head/>
<body>
<xsl:for-each select="body/letter">
<p>
<b>
<xsl:if test="author">
<xsl:text>From </xsl:text>
<xsl:value-of select="author"/>
</xsl:if>
<xsl:if test="author and recipient">
<xsl:text> to </xsl:text>
</xsl:if>
<xsl:if test="not(author) and recipient">
<xsl:text>To </xsl:text>
</xsl:if>
<xsl:if test="recipient">
<xsl:value-of select="recipient"/>
<br/>
</xsl:if>
</b>
<xsl:if test="place">
<xsl:value-of select="place"/>
<br/>
</xsl:if>
<xsl:if test="year">
<xsl:value-of select="year"/>
<br/>
</xsl:if>
<xsl:if test="callnumber">
<xsl:value-of select="callnumber"/>
<br/>
</xsl:if>
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
<xsl:template match="collection">
<html>
<head/>
<body>
<xsl:for-each select="body/letter">
<p>
<b>
<xsl:if test="author">
<xsl:text>From </xsl:text>
<xsl:value-of select="author"/>
</xsl:if>
<xsl:if test="author and recipient">
<xsl:text> to </xsl:text>
</xsl:if>
<xsl:if test="not(author) and recipient">
<xsl:text>To </xsl:text>
</xsl:if>
<xsl:if test="recipient">
<xsl:value-of select="recipient"/>
<br/>
</xsl:if>
</b>
<xsl:if test="place">
<xsl:value-of select="place"/>
<br/>
</xsl:if>
<xsl:if test="year">
<xsl:value-of select="year"/>
<br/>
</xsl:if>
<xsl:if test="callnumber">
<xsl:value-of select="callnumber"/>
<br/>
</xsl:if>
</p>
</xsl:for-each>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Exercise 4.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:template match="collection"> <table> <tr> <td> <b>Sender</b></td> <td> <b>Recipient</b></td> <td> <b>Year</b></td> </tr> <xsl:for-each select="body/letter"> <tr> <td> <xsl:value-of select="author"/> </td> <td> <xsl:value-of select="recipient"/> </td> <td> <xsl:value-of select="year"/> </td> </tr> </xsl:for-each> </table> </xsl:template> </xsl:stylesheet>
Exercise 5.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="collection"> <html> <head/> <body> <p> <ul> <xsl:for-each select="body/letter"> <li> <xsl:if test="callnumber"> <b> <xsl:value-of select="callnumber"/> </b> <br/> </xsl:if> <xsl:if test="place"> <xsl:value-of select="place"/> <br/> </xsl:if> <xsl:if test="year"> <xsl:value-of select="year"/> <br/> </xsl:if> <xsl:if test="year"> <xsl:value-of select="language"/> </xsl:if> </li> </xsl:for-each> </ul> </p> </body> </html> </xsl:template> </xsl:stylesheet>
Exercise 6.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:template match="collection"> <html> <head/> <body> <ul> <xsl:for-each select="body/letter"> <li> <text>Author: </text> <xsl:value-of select="author"/> <br/> <text>Recipient: </text> <xsl:value-of select="recipient"/> <br/> <xsl:if test="year"> <xsl:value-of select="year"/> <br/> </xsl:if> <xsl:for-each select="annotations/note"> <xsl:value-of select="."/><br/> </xsl:for-each> </li> </xsl:for-each> </ul> </body> </html> </xsl:template> </xsl:stylesheet>
Exercise 7.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:template match="collection"> <html> <head/> <body> <ul> <xsl:for-each select="body/letter"> <xsl:if test="year < 1900" > <li> <text>Author: </text> <xsl:value-of select="author"/> <br/> <text>Recipient: </text> <xsl:value-of select="recipient"/> <br/> <xsl:if test="year"> <xsl:value-of select="year"/> <br/> </xsl:if> <xsl:for-each select="annotations/note"> <xsl:value-of select="."/><br/> </xsl:for-each> </li> </xsl:if> </xsl:for-each> </ul> </body> </html> </xsl:template> </xsl:stylesheet>
Exercise 8.
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs" version="2.0"> <xsl:template match="collection"> <html> <head/> <body> <p> <xsl:text>The collection contains </xsl:text> <xsl:value-of select="count( body/letter )"/> <xsl:text> letters.</xsl:text> </p> <p> <xsl:value-of select="count( body/letter[ year < 1900 ] )"/> <xsl:text> of these have been written before 1900.</xsl:text> </p> <p> <xsl:text>The collection contains </xsl:text> <xsl:value-of select="count( body/letter[ language/@code = 'eng' ] )"/> <xsl:text> letters in English.</xsl:text> </p> </body> </html> </xsl:template> </xsl:stylesheet>