<?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>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
		<head>
			<title>	Library List </title>
			<!--link rel="stylesheet" href="/assign4_styles.css" type="text/css"/-->
		</head>
		<style>
			body {background-color: CornSilk; font: lucinda sans 10pt; color: Black;
				  line-height: 2;}
			h1{color: Maroon;} h2{font-size: 11pt; color: FireBrick;}
			div {border-bottom: dotted 1px #999999; margin-top: 30px; margin-bottom: 15px;
				padding-bottom: 10px;}
		</style>
		<body>
			<h1> List of Libraries </h1>
			<xsl:apply-templates select="librarylist/library"/>
		</body>
	</html>
</xsl:template>

<xsl:template match="library">
	<div>
		<h2>
			<xsl:value-of select="name/nameEn"/>
			<xsl:text> - </xsl:text>
			<xsl:value-of select="name/nameOther"/>
			(<xsl:value-of select="country"/>)
		</h2>
		<b>Type:</b> <xsl:apply-templates select="type"/>.<br/>
		<b>Address:</b> <xsl:apply-templates select="ADDRESS[@language='EN']"/>. <br/>
		<xsl:if test="count(url) != 0">
			<xsl:apply-templates select="url"/>.<br/>
		</xsl:if>
		<xsl:if test="count(phone) != 0">
			<b>Phone:</b> <xsl:apply-templates select="phone"/>. <br/>
		</xsl:if>
		<xsl:if test="count(onlineContact)>0">
			<xsl:apply-templates select="onlineContact"/><br/>
		</xsl:if>
		<xsl:if test="count(openHours) > 0">
			<b>Open Hours:</b>  <xsl:apply-templates select="openHours"/> <br/>
		</xsl:if>
		<xsl:if test="count(collectionSize)>0">
			<b>Collection Size:</b> <xsl:apply-templates select="collectionSize"/> <br/>
		</xsl:if>
		<xsl:if test="count(rareBooks)>0">
			<b>Rare Books Collection:</b> <xsl:apply-templates select="rareBooks"/>
		</xsl:if>
		
	</div>
</xsl:template>

<xsl:template match="phone">
	<xsl:value-of select="./phoneGeneral"/> (General) 
	<xsl:if test="count(./phoneOther) != 0">.  
		<xsl:value-of select="./phoneOther"/> (Other)
	</xsl:if>
</xsl:template>

<xsl:template match="url">
	<b>Website Homepage </b>- <xsl:value-of select="./urlMain"/> 
	<font size="2"> (<xsl:value-of select="./urlMain/@language"/>). </font> <br/>
	<xsl:if test="count(urlOther)!= 0">
		<b>Webpage available in other languages </b>- 
		<xsl:for-each select="./urlOther">
			<xsl:apply-templates/>
			<font size="2"> (<xsl:value-of select="@language"/>)</font>
		</xsl:for-each>
	</xsl:if>
</xsl:template>

<xsl:template match="openHours">
	<xsl:apply-templates select="./hours"/> 
	<xsl:if test="count(./days) != 0">
		  <xsl:value-of select="./days[@language='EN']"/>.   
	</xsl:if>
</xsl:template>

<xsl:template match="onlineContact">
	<xsl:if test="count(contactForm) >0">
		<b>Please contact the library via Web form:</b> <xsl:value-of select="./contactForm"/>
	</xsl:if>
	<xsl:if test="count(email)>0">
		<b>Please email the library via:</b> <xsl:value-of select="./email"/>
	</xsl:if>
</xsl:template>

<xsl:template match="collectionSize">
	<xsl:variable name="size" select="."/>
	<xsl:value-of select="format-number($size, '#,###,###,###')"/>
</xsl:template>

<xsl:template match="rareBooks">
	<xsl:variable name="size" select="."/>
	<xsl:value-of select="format-number($size, '#,###,###,###')"/>
</xsl:template>

</xsl:stylesheet>