<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
	<xsl:template match="/">
		<html>
			<head>
				<title>
					<xsl:text>Resume - </xsl:text>
					<xsl:apply-templates select="/resume/person/name"/>
				</title>
			</head>
			<body>
				<xsl:apply-templates/>
			</body>
		</html>
	</xsl:template>
	<xsl:template match="person">
		<h1>
			<xsl:apply-templates select="name"/>
		</h1>
		<xsl:apply-templates select="contactInformation"/>
	</xsl:template>
	<xsl:template match="contactInformation">
		<div id="contact">
			<xsl:apply-templates select="address"/>
			<xsl:apply-templates select="email"/>
			<xsl:apply-templates select="telephone"/>
		</div>
	</xsl:template>
	<xsl:template match="person/name | reference/name">
		<xsl:value-of select="firstName"/>
		<xsl:text> </xsl:text>
		<xsl:if test="middleName">
			<xsl:value-of select="middleName"/>
			<xsl:text> </xsl:text>
		</xsl:if>
		<xsl:value-of select="lastName"/>
	</xsl:template>
	<xsl:template match="address">
		<div class="address">
			<xsl:if test="street">
				<xsl:for-each select="street">
					<span class="addressLine">
						<xsl:value-of select="."/>
					</span>
				</xsl:for-each>
			</xsl:if>
			<xsl:if test="city or stateOrProvince or postalCode or country">
				<span class="addressLine">
					<xsl:if test="city">
						<xsl:value-of select="city"/>
						<xsl:text>, </xsl:text>
					</xsl:if>
					<xsl:if test="stateOrProvince">
						<xsl:value-of select="stateOrProvince"/>
						<xsl:text>  </xsl:text>
					</xsl:if>
					<xsl:if test="postalCode">
						<xsl:value-of select="postalCode"/>
						<xsl:text>  </xsl:text>
					</xsl:if>
					<xsl:if test="country">
						<xsl:value-of select="country"/>
						<xsl:text>  </xsl:text>
					</xsl:if>
				</span>
			</xsl:if>
		</div>
	</xsl:template>
	<xsl:template match="telephone">
		<span class="telephone">
			<xsl:value-of select="concat(text(), ' [', @type, ']')"/>
		</span>
	</xsl:template>
	<xsl:template match="startDate | endDate | graduationDate">
		<span class="date">
			<xsl:if test="month">
				<xsl:choose>
					<xsl:when test="month = '01'">January</xsl:when>
					<xsl:when test="month = '02'">February</xsl:when>
					<xsl:when test="month = '03'">March</xsl:when>
					<xsl:when test="month = '04'">April</xsl:when>
					<xsl:when test="month = '05'">May</xsl:when>
					<xsl:when test="month = '06'">June</xsl:when>
					<xsl:when test="month = '07'">July</xsl:when>
					<xsl:when test="month = '08'">August</xsl:when>
					<xsl:when test="month = '09'">September</xsl:when>
					<xsl:when test="month = '10'">October</xsl:when>
					<xsl:when test="month = '11'">November</xsl:when>
					<xsl:when test="month = '12'">December</xsl:when>
				</xsl:choose>
				<xsl:text> </xsl:text>
			</xsl:if>
			<xsl:if test="day">
				<xsl:value-of select="day"/>
				<xsl:text>,</xsl:text>
			</xsl:if>
			<xsl:value-of select="year"/>
		</span>
	</xsl:template>
	<xsl:template match="email">
		<a href="mailto:{text()}" class="email">
			<xsl:value-of select="text()"/>
		</a>
	</xsl:template>
	<xsl:template match="educationHistory">
		<div id="education" class="section">
			<h2>Education</h2>
			<xsl:apply-templates select="educationItem"/>
		</div>
	</xsl:template>
	<xsl:template match="educationItem">
		<div class="item">
			<xsl:apply-templates select="organization"/>
			<span class="degreeName">
				<xsl:value-of select="degreeName"/>
			</span>
			<xsl:apply-templates select="gpa"/>
			<xsl:apply-templates select="dateRange"/>
			<xsl:apply-templates select="graduationDate"/>
			<xsl:apply-templates select="acknowledgements"/>
			<xsl:apply-templates select="coursework"/>
		</div>
	</xsl:template>
	<xsl:template match="gpa">
		<span class="gpa">
			<xsl:text>GPA:  </xsl:text>
			<xsl:value-of select="text()"/>
		</span>
	</xsl:template>
	<xsl:template match="acknowledgements">
		<div class="acknowledgements">
			<ul>
				<xsl:for-each select="acknowledgement">
					<li class="acknowledgement">
						<xsl:value-of select="text()"/>
					</li>
				</xsl:for-each>
			</ul>
		</div>
	</xsl:template>
	<xsl:template match="coursework">
		<div class="coursework">
			<h4>Coursework</h4>
			<ul>
				<xsl:for-each select="course">
					<li class="course">
						<xsl:value-of select="text()"/>
					</li>
				</xsl:for-each>
			</ul>
		</div>
	</xsl:template>
	<xsl:template match="facts">
		<xsl:if test=".//@type='activity' or .//@type='interest'">
			<div id="activities" class="section">
				<h2>Activities and Interests</h2>
				<ul>
					<xsl:for-each select="fact/item[@type='activity' or @type='interest']">
						<li>
							<xsl:apply-templates select="."/>
						</li>
					</xsl:for-each>
				</ul>
			</div>
		</xsl:if>
		<xsl:if test=".//@type='skill'">
			<div id="skills" class="section">
				<h2>Skills</h2>
				<ul>
					<xsl:for-each select="fact/item[@type='skill']">
						<li>
							<xsl:apply-templates select="."/>
						</li>
					</xsl:for-each>
				</ul>
			</div>
		</xsl:if>
		<xsl:if test=".//@type='publication' or .//@type='award'">
			<div id="publications" class="section">
				<h2>Publications and Awards</h2>
				<ul>
					<xsl:for-each select="fact/item[@type='publication' or @type='award']">
						<li>
							<xsl:apply-templates select="."/>
						</li>
					</xsl:for-each>
				</ul>
			</div>
		</xsl:if>
	</xsl:template>
	<xsl:template match="item">
		<xsl:value-of select="text()"/>
		<xsl:if test="../acquired">
			<xsl:text> (</xsl:text>
			<xsl:for-each select="../acquired">
				<a href="#{@id}">
					<xsl:value-of select="//organization[@id = current()/@id]/name"/>
				</a>
				<xsl:if test="position() != last">
					<xsl:text>; </xsl:text>
				</xsl:if>
			</xsl:for-each>
			<xsl:text>)</xsl:text>
		</xsl:if>
	</xsl:template>
	<xsl:template match="employmentHistory">
		<div id="employment" class="section">
			<h2>Employment</h2>
			<xsl:apply-templates select="employmentItem"/>
		</div>
	</xsl:template>
	<xsl:template match="employmentItem">
		<div class="item">
			<xsl:apply-templates select="organization"/>
			<span class="title">
				<xsl:value-of select="jobTitle"/>
			</span>
			<xsl:text>, </xsl:text>
			<xsl:apply-templates select="dateRange"/>
			<xsl:if test="responsibilities">
				<xsl:apply-templates select="responsibilities"/>
			</xsl:if>
		</div>
	</xsl:template>
	<xsl:template match="dateRange">
		<span class="dateRange">
			<xsl:apply-templates select="startDate"/>
			<xsl:text> - </xsl:text>
			<xsl:apply-templates select="endDate"/>
		</span>
	</xsl:template>
	<xsl:template match="responsibilities">
		<div class="responsibilities">
			<ul>
				<xsl:for-each select="responsibility">
					<li>
						<xsl:value-of select="text()"/>
					</li>
				</xsl:for-each>
			</ul>
		</div>
	</xsl:template>
	<xsl:template match="organization">
		<div class="organization">
			<h3>
				<xsl:if test="@id">
					<xsl:attribute name="id"><xsl:value-of select="@id"/></xsl:attribute>
				</xsl:if>
				<xsl:choose>
					<xsl:when test="website">
						<a href="{website}" target="_blank">
							<xsl:value-of select="name"/>
						</a>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="name"/>
					</xsl:otherwise>
				</xsl:choose>
			</h3>
			<span class="orgLocation">
				<xsl:value-of select="address/city"/>
				<xsl:text>, </xsl:text>
				<xsl:value-of select="address/stateOrProvince"/>
			</span>
			<xsl:apply-templates select="reference"/>
		</div>
	</xsl:template>
	<xsl:template match="reference">
		<div class="references">
			<h4>References</h4>
			<span class="refName">
				<xsl:apply-templates select="name"/>
			</span>
			<xsl:apply-templates select="contactInformation"/>
		</div>
	</xsl:template>
</xsl:stylesheet>
