<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:fn="http://www.w3.org/2005/02/xpath-function">

<xsl:key name="month" match="month" use="@id"/>
<xsl:key name="person" match="person" use="@id"/>
<xsl:key name="org" match="org" use="@id"/>
<xsl:key name="pub" match="pub" use="@id"/>
<xsl:key name="event" match="event" use="@id"/>
<xsl:key name="journal" match="journal" use="@id"/>

<xsl:template match="/">
	<xsl:apply-templates />
</xsl:template>

<xsl:template match="cv">

	<html><head>
	<link rel="stylesheet" type="text/css" href="/style.css"/>
	<title>CV - <xsl:value-of select="name" /></title>
	</head><body>

	<h1>CV - <xsl:value-of select="name" /></h1>

	<div class="project">
	<h2>Research interests</h2>
	<xsl:for-each select="interests">
		<li> <xsl:value-of select="text()" /></li>
	</xsl:for-each>
	</div>

	<div class="project">
	<h2>Education</h2>

	<xsl:for-each select="degree">
		<p><xsl:apply-templates /></p>
	</xsl:for-each>
	</div>

	<div class="project">
	<h2>Publications</h2>

	<xsl:apply-templates select="pubs" />
	</div>

	<div class="project">
	<h2>Talks</h2>

	<xsl:apply-templates select="talks"/>
	</div>

	<div class="project">
	<h2>Professional service</h2>

        <xsl:for-each select="service/role">
                <li> <xsl:for-each select="key('event', @event)">
			<a href="{url}"><xsl:value-of select="name" /> (<xsl:value-of select="abbrev" />)</a>
		</xsl:for-each>, <xsl:value-of select="@name"/></li>
        </xsl:for-each>
	<li> External reviewer for: <xsl:for-each select="reviewed/for[1]">
		<xsl:for-each select="key('event', @event)">
			<a href="{url}"><xsl:value-of select="abbrev" /></a>
		</xsl:for-each>
	</xsl:for-each>
	<xsl:for-each select="reviewed/for[position() > 1]">,
		<xsl:for-each select="key('event', @event)">
			<a href="{url}"><xsl:value-of select="abbrev" /></a>
		</xsl:for-each>
	</xsl:for-each></li>
	</div>

	<div class="project">
	<h2>Employment</h2>

	<xsl:for-each select="job">
		<p><xsl:apply-templates /></p>
	</xsl:for-each>
	</div>

	<div class="project">
	<h2>Academic honors</h2>

	<xsl:apply-templates select="honors" />
	</div>

	<div class="project">
	<h2>Experience with software technologies</h2>

	<xsl:apply-templates select="languages" />
	</div>

	<div class="project">
	<h2>Summer schools</h2>

	<xsl:apply-templates select="summer_schools" />
	</div>



	<div class="project">
	<h2>Open Source software</h2>

	<xsl:apply-templates select="software" />
	</div>

	<div class="project">
	<h2>Other activities</h2>

	<xsl:apply-templates select="activities" />
	</div>

	</body></html>

</xsl:template>

<xsl:template match="name">
	<b><xsl:value-of select="text()" /></b><br />
</xsl:template>

<xsl:template match="title">
	<b><xsl:value-of select="text()" /></b><br />
</xsl:template>

<xsl:template match="task">
	<li><xsl:text> </xsl:text><xsl:value-of select="text()" /></li>
</xsl:template>

<xsl:template name="org">
	<xsl:for-each select="key('org', @org)">
		<xsl:choose>
			<xsl:when test="url">
				<a href="{url}"><xsl:value-of select="name" /></a>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="name" />
			</xsl:otherwise>
		</xsl:choose>
		<xsl:for-each select="location">, <xsl:value-of select="text()" />
		</xsl:for-each>
		<xsl:for-each select="note"><xsl:text> </xsl:text><xsl:value-of select="text()" />
		</xsl:for-each>
	</xsl:for-each>
</xsl:template>

<xsl:template match="atOrg">
	<xsl:call-template name="org" /><br />
</xsl:template>

<xsl:template match="advisor">
	<xsl:for-each select="key('person', @person)">
		<b>Advisor:</b><xsl:text> </xsl:text> <a href="{url}">
			<xsl:value-of select="name" />
		</a><br />
	</xsl:for-each>
</xsl:template>

<xsl:template match="boss">
	<xsl:choose>
		<xsl:when test="@title">
			<b><xsl:value-of select="@title" />:</b>
		</xsl:when>
		<xsl:otherwise>
			<b>PI:</b>
		</xsl:otherwise>
	</xsl:choose>
	<xsl:text> </xsl:text> 
	<xsl:for-each select="key('person', @person)">
		<a href="{url}">
			<xsl:value-of select="name" />
		</a><br />
	</xsl:for-each>
</xsl:template>

<xsl:template match="bosses">
	<xsl:choose>
		<xsl:when test="@title">
			<b><xsl:value-of select="@title" />:</b>
		</xsl:when>
		<xsl:otherwise>
			<b>PIs:</b>
		</xsl:otherwise>
	</xsl:choose>
	<xsl:text> </xsl:text>
	<xsl:for-each select="boss[1]">
		<xsl:for-each select="key('person', @person)">
			<a href="{url}">
				<xsl:value-of select="name" />
			</a>
		</xsl:for-each>
	</xsl:for-each>
	<xsl:for-each select="boss[position() > 1]">
		<xsl:for-each select="key('person', @person)">,
			<a href="{url}">
				<xsl:value-of select="name" />
			</a>
		</xsl:for-each>
	</xsl:for-each><br />
</xsl:template>

<xsl:template match="when" name="when">
	<xsl:for-each select="start">
		<xsl:value-of select="month" />/<xsl:value-of select="year" /> -
	</xsl:for-each>
	<xsl:for-each select="end_tbd">
		??
	</xsl:for-each>
	<xsl:for-each select="end_present">
		present
	</xsl:for-each>
	<xsl:for-each select="end">
		<xsl:value-of select="month" />/<xsl:value-of select="year" /><xsl:for-each select="tentative">(expected)</xsl:for-each>
	</xsl:for-each>
	<xsl:for-each select="summers">
		Summers, <xsl:value-of select="from" /> - <xsl:value-of select="to" />
	</xsl:for-each><br />
</xsl:template>

<xsl:template match="thesis">
	<xsl:for-each select="key('pub', @pub)">
		<xsl:choose>
		<xsl:when test="../dontShow">
		<b>Thesis:</b><xsl:text> </xsl:text>
			<xsl:value-of select="title" />
		<br />
		</xsl:when>
		<xsl:otherwise>
		<b>Thesis:</b><xsl:text> </xsl:text> <a href="papers/{@id}/">
			<xsl:value-of select="title" />
		</a><br />
		</xsl:otherwise>
		</xsl:choose>
	</xsl:for-each>
</xsl:template>

<xsl:template match="gpa">
	<i>Cumulative GPA:</i><xsl:text> </xsl:text><xsl:value-of select="text()" /> out of 4.0<br />
</xsl:template>

<xsl:template match="fellowship">
	<li> <b><a href="{url}"><xsl:value-of select="name" /></a> winner</b>,
	<xsl:for-each select="fromOrg">
		<xsl:call-template name="fromOrg" />
	</xsl:for-each>
	<xsl:for-each select="year">
		<xsl:call-template name="year" />
	</xsl:for-each>
	<xsl:for-each select="when">
		<xsl:call-template name="when" />
	</xsl:for-each></li>
</xsl:template>

<xsl:template match="fellowship_honorable">
	<li> <b>Honorable Mention, <a href="{url}"><xsl:value-of select="name" /></a> competition</b>,
	<xsl:for-each select="fromOrg">
		<xsl:call-template name="fromOrg" />
	</xsl:for-each>
	<xsl:for-each select="year">
		<xsl:call-template name="year" />
	</xsl:for-each>
	<xsl:for-each select="when">
		<xsl:call-template name="when" />
	</xsl:for-each></li>
</xsl:template>

<xsl:template match="fromOrg" name="fromOrg">
	<xsl:call-template name="org" />,
</xsl:template>

<xsl:template match="year" name="year">
	<xsl:value-of select="text()" />
</xsl:template>

<xsl:template match="inducted">
	<li><xsl:text> </xsl:text><b>Inducted into <a href="{url}"><xsl:value-of select="name" /></a></b></li>
</xsl:template>

<xsl:template match="a">
	<a href="{@href}"><xsl:value-of select="text()" /></a>
</xsl:template>

<xsl:template match="activity">
	<li><xsl:text> </xsl:text><xsl:apply-templates /></li>
</xsl:template>

<xsl:template match="program">
	<li><xsl:text> </xsl:text><xsl:apply-templates /></li>
</xsl:template>

<xsl:template match="summer_school">
	<li> <b><a href="{url}"><xsl:value-of select="name" /></a></b>,
	<xsl:for-each select="atOrg">
		<xsl:call-template name="org" />, 
	</xsl:for-each>
	<xsl:for-each select="year">
		<xsl:call-template name="year" />
	</xsl:for-each>
	<xsl:for-each select="when">
		<xsl:call-template name="when" />
	</xsl:for-each></li>
</xsl:template>

<xsl:template match="author" name="author">
	<xsl:variable name="authorElem" select="." />
	<xsl:for-each select="key('person', @person)">
		<a href="{url}">
			<xsl:choose>
				<xsl:when test="authorElem/@as">
					<xsl:value-of select="$authorElem/@as" />
				</xsl:when>
				<xsl:when test="citeName">
					<xsl:value-of select="citeName" />
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="name" />
				</xsl:otherwise>
			</xsl:choose>
		</a>
	</xsl:for-each>
</xsl:template>

<xsl:template name="month">
	<xsl:for-each select="key('month', month/@month)"><xsl:value-of select="name" /><xsl:text> </xsl:text></xsl:for-each>
</xsl:template>

<xsl:template match="pubKind">
	<xsl:if test="not(dontShow)">
	<h3><xsl:value-of select="@name"/></h3>

	<xsl:apply-templates/>
	</xsl:if>
</xsl:template>

<xsl:template match="pub">
	<p><xsl:for-each select="author[1]">
		<xsl:call-template name="author" />
	</xsl:for-each>
	<xsl:for-each select="author[position() > 1]">, <xsl:call-template name="author" />
	</xsl:for-each>.
	<a href="papers/{@id}/">
		<xsl:value-of select="title" />
	</a>.
	<xsl:for-each select="type">
		<xsl:value-of select="text()" />.
	</xsl:for-each>
	<xsl:for-each select="report">
		Technical Report <xsl:value-of select="text()" />.
	</xsl:for-each>
	<xsl:for-each select="proceedings">
		<xsl:for-each select="key('event', @event)">
			Proceedings of the <xsl:choose><xsl:when test="url"><a>
				<xsl:attribute name="href"><xsl:value-of select="url" /></xsl:attribute>
				<xsl:value-of select="name" /> (<xsl:value-of select="abbrev" />)</a>
			</xsl:when><xsl:otherwise>
				<xsl:value-of select="name" /> (<xsl:value-of select="abbrev" />)
			</xsl:otherwise></xsl:choose>
			<xsl:for-each select="publisher">
				<xsl:for-each select="key('org', @org)">, <xsl:value-of select="name" />
				</xsl:for-each></xsl:for-each>
		</xsl:for-each>
		<xsl:if test="@lncs">, Lecture Notes in Computer Science <xsl:value-of select="@lncs" />, Springer-Verlag</xsl:if>.
		<xsl:for-each select="key('event', @event)">
			<xsl:if test="year">
				<xsl:call-template name="month" />
				<xsl:value-of select="year" />.
			</xsl:if>
		</xsl:for-each>
	</xsl:for-each>
	<xsl:for-each select="journal">
		<xsl:for-each select="key('journal', @journal)">
			<xsl:choose><xsl:when test="url"><a>
				<xsl:attribute name="href"><xsl:value-of select="url" /></xsl:attribute>
				<xsl:value-of select="name" /> (<xsl:value-of select="abbrev" />)</a>.
			</xsl:when><xsl:otherwise>
				<xsl:value-of select="name" /> (<xsl:value-of select="abbrev" />).
			</xsl:otherwise></xsl:choose>
		</xsl:for-each>
                <xsl:value-of select="@volume"/>. <xsl:value-of select="@pages"/>, <xsl:value-of select="@year"/>.
		<xsl:for-each select="key('journal', @journal)">
			<xsl:for-each select="publisher">
				<xsl:for-each select="key('org', @org)"><xsl:value-of select="name" />.
				</xsl:for-each></xsl:for-each>
		</xsl:for-each>
	</xsl:for-each>
	<xsl:for-each select="atOrg">
		<xsl:call-template name="org" />.
	</xsl:for-each>
	<xsl:call-template name="month" />
	<xsl:for-each select="year">
		<xsl:value-of select="text()" />.
	</xsl:for-each>
	<xsl:if test="status"><xsl:value-of select="status"/>.</xsl:if>
	</p>
</xsl:template>

<xsl:template match="category">
	<b><xsl:value-of select="@name" /></b>: <xsl:apply-templates /><br/>
</xsl:template>

<xsl:template match="talk">
	<p><xsl:choose><xsl:when test="@paper">
		<a href="papers/{@paper}/">
			<xsl:value-of select="title" />
		</a>.
	</xsl:when><xsl:otherwise>
		<xsl:value-of select="title" />.
	</xsl:otherwise></xsl:choose>
	<xsl:for-each select="key('event', @event)">
		<xsl:choose><xsl:when test="url"><a>
			<xsl:attribute name="href"><xsl:value-of select="url" /></xsl:attribute>
			<xsl:value-of select="abbrev" /></a>
		</xsl:when><xsl:otherwise>
			<xsl:value-of select="abbrev" />
		</xsl:otherwise></xsl:choose>.
		<xsl:if test="year">
			<xsl:call-template name="month" />
			<xsl:value-of select="year" />.
		</xsl:if>
	</xsl:for-each></p>
</xsl:template>

<xsl:template match="shortName" />
<xsl:template match="shortOrg" />

</xsl:stylesheet>
