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

<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:exsl="http://exslt.org/common"
	xsl:extension-element-prefixes="exsl">

<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="/">
	<papers>
	<xsl:apply-templates />
	</papers>
</xsl:template>

<xsl:template match="cv">
	<xsl:apply-templates select="pubs" />
</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="pub">
	<xsl:if test="not(../dontShow)">
	<xsl:document href="public_html/papers/{@id}/index.html">
	<html><head>
	<link rel="stylesheet" type="text/css" href="/style.css"/>
	<title><xsl:value-of select="title" /></title>
	</head><body>
	<h1><xsl:value-of select="title" /></h1>
	<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 <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>
                <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>
	<br /><hr />
	<div class="project">
	<xsl:for-each select="abstract">
		<p><xsl:apply-templates /></p>
	</xsl:for-each>
	</div>
	<hr />
	<xsl:choose>
		<xsl:when test="comingSoon">
			Coming soon!
		</xsl:when>
		<xsl:otherwise>
                        <xsl:choose>
                                <xsl:when test="nops">[ <a href="{@id}.pdf">PDF</a> ]</xsl:when>
                                <xsl:otherwise>[ <a href="{@id}.ps">PS</a> | <a href="{@id}.pdf">PDF</a> ]</xsl:otherwise>
                        </xsl:choose>
			<xsl:for-each select="proceedings">
				<xsl:for-each select="key('event', @event)">
					<xsl:for-each select="copyright">
						Copyright
						<xsl:value-of select="year" />
						<xsl:text> </xsl:text>
						<xsl:for-each select="key('org', @org)">
							<a href="{url}"><xsl:value-of select="abbrev" /></a>
						</xsl:for-each>
					</xsl:for-each>
				</xsl:for-each>
			</xsl:for-each>
			<xsl:for-each select="atOrg">
				Copyright <xsl:value-of select="../year" />
				<xsl:text> </xsl:text>
				<xsl:call-template name="org" />.
			</xsl:for-each>
			<xsl:for-each select="journal">
                    		Copyright <xsl:value-of select="@year" />
                                <xsl:text> </xsl:text>
                                <xsl:for-each select="key('journal', @journal)/publisher">
        				<xsl:call-template name="org" />
                                </xsl:for-each>
			</xsl:for-each>
		</xsl:otherwise>
	</xsl:choose>
	</body></html>
	</xsl:document></xsl:if>
</xsl:template>

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

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

</xsl:stylesheet>
