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

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<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>
	<title>Publications - <xsl:value-of select="name" /></title>
	</head><body>

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

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

	</body></html>

</xsl:template>

<xsl:template name="org">
	<xsl:for-each select="key('org', @org)">
		<xsl:choose>
			<xsl:when test="url">
				<a>
					<xsl:attribute name="href">
						<xsl:value-of select="url" />
					</xsl:attribute>
					<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="author" name="author">
	<xsl:variable name="authorElem" select="." />
	<xsl:for-each select="key('person', @person)">
		<a>
			<xsl:attribute name="href">
				<xsl:value-of select="url" />
			</xsl:attribute>
			<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)">
	<h2><xsl:value-of select="@name"/></h2>

	<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>
		<xsl:attribute name="href">
			<xsl:value-of select="@id" />/</xsl:attribute>
		<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:text> </xsl:text>
				<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 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>
	<xsl:for-each select="summary">
		<blockquote><i><xsl:apply-templates /></i></blockquote>
	</xsl:for-each>
	</p>
</xsl:template>

<xsl:template match="a">
	<a href="{@href}"><xsl:apply-templates/></a>
</xsl:template>

</xsl:stylesheet>
