<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
	<xsl:template match="/">
		<HTML>
			<head>
				<title>Booksale Info</title>
			</head>
			<BODY style="background-color: LightBlue">
				<div style="font-size: 22pt; font-weight: bold">Visit Our Libraries for the Annual Booksale</div>
				<div style="font-size: 12pt; text-indent: 30px"><ul><li><xsl:value-of select="count(library_info/library/booksale/bookgroup/book)"/> books available at an average price of $<xsl:value-of select="floor(100 * sum(library_info/library/booksale/bookgroup/book/price) div count(library_info/library/booksale/bookgroup/book)) div 100"/>!</li></ul></div>


				<xsl:for-each select="library_info/library/booksale">
					<xsl:apply-templates select="../library_name"/>
					<xsl:apply-templates select="bookgroup/genre_name"/>
				</xsl:for-each>
			</BODY>
		</HTML>
	</xsl:template>
	<xsl:template match="genre_name">
		<div style="font-size: 13pt; font-weight: bold; text-indent: 25px">
		<xsl:value-of select="."/>
		</div>
		<ul>
		<xsl:for-each select="../book">
			<div style="text-indent: 30px">
			<li><xsl:apply-templates select="title"/> 
			by <xsl:for-each select="author">
				<xsl:choose>
					<xsl:when test="position() != 1">
						and <xsl:value-of select="concat(first,' ',middle,' ',last)"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="concat(first,' ',middle,' ',last)"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:for-each>
			for $<xsl:apply-templates select="price"/></li>
			</div>
		</xsl:for-each></ul>
	</xsl:template>
	<xsl:template match="title">
		<xsl:value-of select="."/>
	</xsl:template>
	<xsl:template match="library_name">
		<p style="font-size: 16pt; font-weight: bold; text-decoration:underline">The <xsl:value-of select="."/> has the following books for sale</p>
	</xsl:template>
</xsl:stylesheet>