<?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:output method="text" />

<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">
<xsl:value-of select="name" />\n<xsl:for-each select="address"><xsl:value-of select="office" /><xsl:for-each select="org">\n<xsl:value-of select="text()" /></xsl:for-each>\n<xsl:value-of select="city" />\n<xsl:value-of select="country" />\n<xsl:value-of select="email" />\n<xsl:value-of select="url" /></xsl:for-each>

=========
Objective
=========

<xsl:value-of select="objective"/>

=========
Education
=========<xsl:for-each select="degree">
	<xsl:call-template name="degree" />
</xsl:for-each>

=====================
Software technologies
=====================
<xsl:for-each select="languages/category">\n* <xsl:value-of select="@name" />: <xsl:value-of select="text()" />
</xsl:for-each>

===============
Academic honors
===============
<xsl:for-each select="honors/*">\n* <xsl:apply-templates select="." /></xsl:for-each>

==========
Employment
==========
<xsl:for-each select="job">
	<xsl:call-template name="job" />
</xsl:for-each>
===========
Citizenship
===========

<xsl:value-of select="citizenship" />

====================
Open source software
====================
<xsl:for-each select="software/program"><xsl:apply-templates select="." /></xsl:for-each>

================
Other activities
================
<xsl:for-each select="activities/activity"><xsl:apply-templates select="." /></xsl:for-each>

============
Publications
============<xsl:for-each select="pubs/pubKind"><xsl:if test="not(dontShow)">\n\n<xsl:value-of select="@name"/>:
<xsl:for-each select="pub">\n* <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>. <xsl:value-of select="title" />. <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:value-of select="name" /><xsl:for-each select="publisher"><xsl:for-each select="key('org', @org)">, <xsl:value-of select="name" /> (<xsl:value-of select="abbrev" />)</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="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:for-each select="journal"><xsl:for-each select="key('journal', @journal)"><xsl:value-of select="name" /></xsl:for-each>. <xsl:value-of select="@volume"/>. <xsl:value-of select="@pages"/>, <xsl:value-of select="@year"/>. </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></xsl:for-each>
</xsl:if></xsl:for-each>\n</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></xsl:template>

<xsl:template name="degree"><xsl:for-each select="atOrg[1]">
		<xsl:for-each select="key('org', @org)">\n\n* <xsl:value-of select="name" /><xsl:for-each select="location">, <xsl:value-of select="text ()" /></xsl:for-each></xsl:for-each>\n</xsl:for-each><xsl:for-each select="atOrg[position() > 1]">	<xsl:for-each select="key('org', @org)"><xsl:value-of select="name" />\n</xsl:for-each>
	</xsl:for-each><xsl:value-of select="name" />
	<xsl:for-each select="when">\n<xsl:call-template name="when" /></xsl:for-each>
	<xsl:for-each select="advisor"><xsl:for-each select="key('person', @person)">\nAdvisor: <xsl:value-of select="name" /></xsl:for-each></xsl:for-each><xsl:for-each select="gpa">\nCumulative GPA: <xsl:value-of select="text ()" /> out of 4.0</xsl:for-each><xsl:for-each select="thesis"><xsl:for-each select="key('pub', @pub)">\nThesis: <xsl:value-of select="title" /></xsl:for-each></xsl:for-each>
</xsl:template>

<xsl:template match="author" name="author">
	<xsl:variable name="authorElem" select="." />
	<xsl:for-each select="key('person', @person)">
		<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>
	</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 name="org">
	<xsl:for-each select="key('org', @org)">
		<xsl:value-of select="name" />
		<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 name="bosses"><xsl:choose><xsl:when test="@title"><xsl:value-of select="@title" /></xsl:when><xsl:otherwise>PIs</xsl:otherwise></xsl:choose>: <xsl:for-each select="boss[1]"><xsl:for-each select="key('person', @person)"><xsl:value-of select="name" /></xsl:for-each></xsl:for-each> <xsl:for-each select="boss[position() > 1]"><xsl:for-each select="key('person', @person)">, <xsl:value-of select="name" /></xsl:for-each></xsl:for-each></xsl:template>

<xsl:template name="job" match="job">\n* <xsl:value-of select="title" /><xsl:for-each select="atOrg">\n<xsl:call-template name="org" /></xsl:for-each>\n<xsl:for-each select="when"><xsl:call-template name="when" /></xsl:for-each><xsl:for-each select="boss">\n<xsl:choose><xsl:when test="@title"><xsl:value-of select="@title" /></xsl:when><xsl:otherwise>PI</xsl:otherwise></xsl:choose>: <xsl:for-each select="key('person', @person)"><xsl:value-of select="name" /></xsl:for-each></xsl:for-each>\n<xsl:for-each select="bosses"><xsl:call-template name="bosses" />\n</xsl:for-each></xsl:template>

<xsl:template match="fellowship"><xsl:value-of select="name" /> winner, <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></xsl:template>

<xsl:template match="fellowship_honorable">Honorable Mention, <xsl:value-of select="name" /> competition, <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></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">Inducted into <xsl:value-of select="name" /></xsl:template>

<xsl:template match="summer_school">
	* <xsl:value-of select="name" />, <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>
</xsl:template>

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

<xsl:template match="activity">\n* <xsl:apply-templates /></xsl:template>

<xsl:template match="program">\n* <xsl:apply-templates /></xsl:template>

</xsl:stylesheet>
