<?xml version="1.0" encoding="UTF-8"?>
<!-- $Id: sharef2html.xsl 524 2006-06-29 20:38:52Z dret $ -->
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xpath-default-namespace="http://dret.net/xmlns/sharef" xmlns:sharef="http://dret.net/xmlns/sharef" xmlns="http://www.w3.org/1999/xhtml" xmlns:html="http://www.w3.org/1999/xhtml">
	<xsl:include href="message.xsl"/>
	<xsl:include href="common_export.xsl"/>
	<!-- include the list of sharef elements that will be stripped from whitespace text nodes -->
	<xsl:include href="sharef_strip_space.xsl"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- primary sort key -->
	<xsl:param name="htmlsort1" select="'date'"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- secondary sort key -->
	<xsl:param name="htmlsort2" select="'name'"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- controls whether only a list is created ('listonly'), or individual pages for all references ('refpages') -->
	<xsl:param name="refpage" select="'listonly'"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- URI prefix for DOIs -->
	<xsl:param name="DOI" select="'http://dx.doi.org/'"/>
	<xsl:variable name="DOI-param" select="if ($DOI eq 'veryunlikelystringvalue') then '' else $DOI"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- URI prefix for the OpenURL resolver -->
	<xsl:param name="OpenURL" select="'http://sfx.ethz.ch:9003/sfx_local'"/>
	<xsl:variable name="OpenURL-param" select="if ($OpenURL eq 'veryunlikelystringvalue') then '' else $OpenURL"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- URI prefix for the ISBN resolver -->
	<xsl:param name="ISBN" select="'http://isbn.nu/'"/>
	<xsl:variable name="ISBN-param" select="if ($ISBN eq 'veryunlikelystringvalue') then '' else $ISBN"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- generate Google links (no/title/titleauthor) -->
	<xsl:param name="google" select="'titleauthor'"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- URI suffix for generated HTML pages (used for creating files) -->
	<xsl:param name="htmlfilesuffix" select="'.html'"/>
	<xsl:variable name="filesuffix" select="if ($htmlfilesuffix eq 'veryunlikelystringvalue') then '' else if (not(starts-with($htmlfilesuffix,'.'))) then concat('.',$htmlfilesuffix) else $htmlfilesuffix"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- URI suffix for links to HTML pages (links in created files to created files) -->
	<xsl:param name="htmllinksuffix" select="'.html'"/>
	<xsl:variable name="linksuffix" select="if ( $htmllinksuffix eq 'veryunlikelystringvalue' ) then '' else if (not(starts-with($htmllinksuffix,'.'))) then concat('.',$htmllinksuffix) else $htmllinksuffix"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- prefix (base URI) for links to HTML pages (links in created files to created files) -->
	<xsl:param name="linkbase" select="''"/>
	<xsl:variable name="linkbase-param" select="if ( $linkbase eq 'veryunlikelystringvalue' ) then '' else $linkbase"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- controls whether the reference ID will be displayed -->
	<xsl:param name="showrefid" select="'show'"/>
	<xsl:variable name="showid" select="if ( $showrefid eq 'show' ) then true() else false()"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- flag for controlling the generation of an author index -->
	<xsl:param name="authorindex" select="'yes'"/>
	<xsl:variable name="AuthorIndex" select="if ( $authorindex eq 'yes' ) then true() else false()"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- flag for controlling the generation of a title index -->
	<xsl:param name="titleindex" select="'no'"/>
	<xsl:variable name="TitleIndex" select="if ( $titleindex eq 'yes' ) then true() else false()"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- flag for controlling the generation of keyword and association indices -->
	<xsl:param name="definitionindex" select="'no'"/>
	<xsl:variable name="keywordindex" select="if ( contains($definitionindex, 'keyword') ) then true() else false()"/>
	<xsl:variable name="associationindex" select="if ( contains($definitionindex, 'association') ) then true() else false()"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- flag for controlling whether the abstract field should be output -->
	<xsl:param name="abstract" select="'simple'"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- flag for controlling whether the annotation field should be output -->
	<xsl:param name="annotation" select="'simple'"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- result-document prefix for the generated html files -->
	<xsl:param name="html_dir" select="''"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- result-document encoding for the generated html files -->
	<xsl:param name="html_encoding" select="'UTF-8'"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- the parameter document (required for various formatting aspects of sharef2html.xsl) -->
	<xsl:param name="parameters" select="doc('sharef2html.xml')"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<xsl:key name="refkey" match="ref" use="@id"/>
	<xsl:key name="referencekey" match="/bibliography/reference | /bibliography/shadow" use="@id"/>
	<xsl:key name="referencekey" match="/bibliography/reference | /bibliography/shadow" use="@name"/>
	<xsl:key name="referencekey-nohelper" match="/bibliography/reference[not(string(@helper) eq 'true')] | /bibliography/shadow[not(string(@helper) eq 'true')]" use="@id"/>
	<xsl:key name="referencekey-nohelper" match="/bibliography/reference[not(string(@helper) eq 'true')] | /bibliography/shadow[not(string(@helper) eq 'true')]" use="@name"/>
	<xsl:key name="referencename" match="/bibliography/reference[not(string(@helper) eq 'true')] | /bibliography/shadow[not(string(@helper) eq 'true')]" use="if (exists(@name)) then @name else sharef:generate-ref-name(string(names[@type eq 'sharef:author'][1]/(name | person/surname)[1]), string(date/@value))"/>
	<xsl:key name="keywordkey" match="/bibliography/keyworddef" use="@id"/>
	<xsl:key name="referencekeywordkey" match="/bibliography/reference[not(string(@helper) eq 'true')] | /bibliography/shadow[not(string(@helper) eq 'true')]" use=".//keywordref/@type"/>
	<xsl:key name="associationkey" match="/bibliography/associationdef" use="@id"/>
	<xsl:key name="xrefkey" match="xref" use="@type"/>
	<xsl:key name="referenceassociationkey" match="/bibliography/reference[not(string(@helper) eq 'true')] | /bibliography/shadow[not(string(@helper) eq 'true')]" use=".//xref/@type"/>
	<xsl:key name="associatedkey" match="xref" use="@target"/>
	<xsl:key name="associatedkey-nohelper" match="/bibliography/reference[not(string(@helper) eq 'true')]//xref | /bibliography/shadow[not(string(@helper) eq 'true')]//xref" use="@target"/>
	<xsl:key name="crossrefkey" match="/bibliography/reference[not(string(@helper) eq 'true')][exists(@crossref)]" use="@crossref"/>
	<xsl:key name="generatedidkey" match="/refs/ref" use="@nodeid"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<xsl:variable name="document" select="."/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- this variable and the following defininitions are for testing purposes only (only used in code shielded by $drettest) -->
	<xsl:variable xmlns:drettest="http://dret.net/xmlns/drettest" name="drettest" select="true()"/>
	<xsl:variable name="dretbiblio" select="if ( $drettest ) then document('dretbiblio.xml') else ()"/>
	<xsl:key name="topickey" match="topic" use="@TID" xpath-default-namespace=""/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- the footer used for all generated HTML pages -->
	<xsl:variable name="footer">
		<div class="footnote">
			<hr/>
			<p>
				<xsl:text>Generated by </xsl:text>
				<code>
					<a href="http://dret.net/projects/sharef/">sharef2html</a>
				</code>
				<xsl:text> on </xsl:text>
				<xsl:value-of select="substring(string(current-date()), 1, 10)"/>
				<xsl:text>, </xsl:text>
				<xsl:value-of select="substring(string(current-time()), 1, 8)"/>
				<xsl:text>.</xsl:text>
			</p>
		</div>
	</xsl:variable>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- percentage per pass (for calculating the progress messages) -->
	<xsl:variable name="percentage" select="99 div (3 + number($AuthorIndex) + number($TitleIndex) + number($keywordindex) + number($associationindex))"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- the input document -->
	<xsl:variable name="doc" select="."/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- the css name -->
	<xsl:variable name="cssname" select="'sharef.css'"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- the cvs id of the current version -->
	<xsl:variable name="cvsid" select="'$Id: sharef2html.xsl 524 2006-06-29 20:38:52Z dret $'"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<xsl:output name="xhtml" method="xhtml" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" exclude-result-prefixes="xs sharef html"/>
	<xsl:output name="xml" method="xml" indent="no" exclude-result-prefixes="xs sharef html"/>
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
	<xsl:variable name="reflist_nocross">
		<refs xmlns="http://dret.net/xmlns/sharef">
			<xsl:variable name="iteration" select="/bibliography/reference | /bibliography/shadow[not(empty(key('referencekey', @source)))]"/>
			<xsl:variable name="number" select="count($iteration)"/>
			<xsl:for-each select="$iteration">
				<xsl:if test="ceiling($percentage * (position() div $number)) != ceiling($percentage * ((position()-1) div $number))">
					<xsl:call-template name="message">
						<xsl:with-param name="level" select="'progress'"/>
						<xsl:with-param name="text" select="ceiling($percentage * (position() div $number))"/>
					</xsl:call-template>
				</xsl:if>
				<xsl:variable name="ref-author" select="string((self::reference | key('referencekey', self::shadow/@source))/names[@type eq 'sharef:author'][1]/(name | person/surname)[1])"/>
				<xsl:variable name="ref-date" select="string((self::reference | key('referencekey', self::shadow/@source))/date/@value)"/>
				<!-- this is the reference name as given or computed, but not necessarily unique -->
				<xsl:variable name="ref-name" select="if (@name ne '') then @name else sharef:generate-ref-name($ref-author, $ref-date)"/>
				<!-- this is the generated node id of the reference/shadow entry -->
				<xsl:variable name="ref-id" select="generate-id()"/>
				<!-- if the name is not unique, it is made unique by appending a postfix (letters a-z or letter/digit if letters a-z are not sufficient) -->
				<xsl:variable name="unique-ref-name" select="concat($ref-name, if (count(key('referencename', $ref-name)) le 1) then '' else if (count(preceding-sibling::* intersect key('referencename', $ref-name)) le 25) then codepoints-to-string(count(preceding-sibling::* intersect key('referencename', $ref-name)) + 97) else concat('z', count(preceding-sibling::* intersect key('referencename', $ref-name) - 25)))"/>
				<!-- in the following element, the key* attributes are the sort keys for the second pass and they must take into account crossref and shadow entries -->
				<ref id="{ if (exists(@id)) then @id else $unique-ref-name }" gen-id="{ $unique-ref-name }" key1="{ if (lower-case(sharef:refkey(if (self::reference) then . else key('referencekey', @source), $htmlsort1)) ne '') then lower-case(sharef:refkey(if (self::reference) then . else key('referencekey', @source), $htmlsort1)) else lower-case(sharef:refkey(key('referencekey', @crossref), $htmlsort1)) }" key2="{ if (lower-case(sharef:refkey(if (self::reference) then . else key('referencekey', @source), $htmlsort2)) ne '') then lower-case(sharef:refkey(if (self::reference) then . else key('referencekey', @source), $htmlsort2)) else lower-case(sharef:refkey(key('referencekey', @crossref), $htmlsort2)) }" class="{ local-name() }" nodeid="{ $ref-id }">
					<xsl:if test="@name ne ''">
						<!-- a name is only assigned if there really was a name attribute on the entry, otherwise there will only be an id -->
						<xsl:attribute name="name" select="@name"/>
					</xsl:if>
					<xsl:if test="@helper eq 'true'">
						<xsl:attribute name="helper" select="'true'"/>
					</xsl:if>
					<xsl:if test="exists(self::shadow)">
						<!-- for shadows, the source of the shadow is stored -->
						<xsl:attribute name="shadow" select="@source"/>
					</xsl:if>
					<type>
						<xsl:value-of select="(self::reference | key('referencekey', self::shadow/@source))/@type"/>
					</type>
					<xsl:choose>
						<xsl:when test="starts-with(@src-info, 'bibtex:line-')">
							<source>BibTeX (Line <xsl:value-of select="substring-after(@src-info, 'bibtex:line-')"/>)</source>
						</xsl:when>
						<xsl:when test="starts-with(@src,'endnote')">
							<source>Endnote <xsl:value-of select="substring-before(substring-after(@src, 'endnote'),':')"/> (Entry type <xsl:value-of select="substring-after(@src, ':')"/>)</source>
						</xsl:when>
					</xsl:choose>
					<xsl:variable name="shadow" select="self::shadow"/>
					<!-- this variable keeps track of the original shadow entry (for the shadow's annotations) -->
					<xsl:for-each select="self::reference | key('referencekey', self::shadow/@source)">
						<!-- this changes the context to the source of a shadow, if the processed entry is a shadow -->
						<sharef:text xmlns="http://www.w3.org/1999/xhtml">
							<xsl:if test="exists(names[@type eq 'sharef:author'])">
								<span title="Author(s)" class="author">
									<xsl:call-template name="process_names">
										<xsl:with-param name="node" select="names[@type eq 'sharef:author']"/>
										<xsl:with-param name="index" select="'yes'"/>
									</xsl:call-template>
								</span>
								<xsl:choose>
									<xsl:when test="exists(names[@type eq 'sharef:editor']) and not(exists(title[string(@type) ne 'sharef:primaryTitle']))">
										<xsl:value-of select="if (count(names[@type eq 'sharef:author']) eq 1 ) then ' (Auth.)' else '( Auths.)'"/>
									</xsl:when>
									<xsl:otherwise>
										<xsl:text>, </xsl:text>
									</xsl:otherwise>
								</xsl:choose>
							</xsl:if>
							<xsl:if test="exists(names[@type eq 'sharef:editor']) and not(exists(title[@type ne 'sharef:primaryTitle']))">
								<xsl:if test="exists(names[@type eq 'sharef:author'])">
									<!-- this means there is an author list before the editor list, both should be separated by a comma -->
									<xsl:text>, </xsl:text>
								</xsl:if>
								<span title="Editor(s)" class="editor">
									<xsl:call-template name="process_names">
										<xsl:with-param name="node" select="names[@type eq 'sharef:editor']"/>
									</xsl:call-template>
								</span>
								<xsl:value-of select="if (count(names[@type eq 'sharef:editor']) eq 1 ) then ' (Ed.)' else ' (Eds.)'"/>
								<xsl:text>, </xsl:text>
							</xsl:if>
							<span title="Title" class="title">
								<xsl:variable name="title" select="title[@type eq 'sharef:primaryTitle']/text()"/>
								<xsl:choose>
									<xsl:when test="$TitleIndex">
										<a title='Title Index: "{normalize-space($title)}"' href="{$linkbase-param}{ if ( $refpage eq 'refpages' ) then '../' else '' }{concat('titles', $linksuffix, '#', sharef:target(.))}">
											<xsl:value-of select="normalize-space($title)"/>
										</a>
									</xsl:when>
									<xsl:otherwise>
										<xsl:value-of select="normalize-space($title)"/>
									</xsl:otherwise>
								</xsl:choose>
							</span>
							<xsl:for-each select="howpublished/text()">
								<xsl:text>, </xsl:text>
								<span title="howpublished">
									<xsl:value-of select="normalize-space(.)"/>
								</span>
							</xsl:for-each>
							<xsl:if test="exists(title[@type ne 'sharef:primaryTitle'])">
								<xsl:for-each select="title[@type = ('sharef:secondaryTitle', 'sharef:bookTitle')]">
									<xsl:if test="position() eq 1">
										<xsl:text>, In: </xsl:text>
									</xsl:if>
									<span title="Title" class="othertitle">
										<xsl:value-of select="normalize-space(text())"/>
									</span>
									<xsl:if test="position() ne last()">
										<xsl:text>, </xsl:text>
									</xsl:if>
								</xsl:for-each>
								<xsl:if test="exists(names[@type eq 'sharef:editor'])">
									<xsl:text>, </xsl:text>
									<span title="Editor(s)" class="editor">
										<xsl:call-template name="process_names">
											<xsl:with-param name="node" select="names[@type eq 'sharef:editor']"/>
										</xsl:call-template>
										<xsl:value-of select="if (count(names[@type eq 'sharef:editor']) eq 1 ) then ' (Ed.)' else '( Eds.)'"/>
									</span>
								</xsl:if>
								<xsl:for-each select="title[@type = ('sharef:seriesTitle', 'sharef:collectionTitle', 'sharef:conferenceName', 'sharef:academicDepartment')]">
									<xsl:text>, </xsl:text>
									<span title="Title" class="othertitle">
										<xsl:value-of select="normalize-space(text())"/>
									</span>
								</xsl:for-each>
							</xsl:if>
							<xsl:for-each select="publisher/text()">
								<xsl:text>, </xsl:text>
								<span title="Publisher" class="publisher">
									<xsl:value-of select="normalize-space(.)"/>
								</span>
							</xsl:for-each>
							<xsl:for-each select="organization/text()">
								<xsl:text>, </xsl:text>
								<span title="Organization" class="organization">
									<xsl:value-of select="normalize-space(.)"/>
								</span>
							</xsl:for-each>
							<xsl:for-each select="address/text()">
								<xsl:text>, </xsl:text>
								<span title="Address" class="address">
									<xsl:value-of select="normalize-space(.)"/>
								</span>
							</xsl:for-each>
							<xsl:for-each select="title[@type eq 'sharef:seriesTitle']/text()">
								<xsl:text>, </xsl:text>
								<span title="Series" class="series">
									<xsl:value-of select="normalize-space(.)"/>
								</span>
							</xsl:for-each>
							<xsl:if test="exists(volume/text()) or exists(number/text()) or exists(pages/text())">
								<xsl:text>, </xsl:text>
								<span class="volnumpage">
									<xsl:choose>
										<xsl:when test="exists(volume/text()) and exists(number/text())">
											<xsl:value-of select="concat(volume/text(), '(', number/text(), ')')"/>
										</xsl:when>
										<xsl:when test="exists(volume/text())">
											<xsl:value-of select="concat('Vol. ', volume/text())"/>
											<xsl:if test="exists(pages/text())">
												<xsl:text>, </xsl:text>
											</xsl:if>
										</xsl:when>
										<xsl:when test="exists(number/text())">
											<xsl:if test="number/text() castable as xs:integer">
												<!-- only generate the "No. " text if the number element really is a number -->
												<xsl:text>No. </xsl:text>
											</xsl:if>
											<xsl:value-of select="number/text()"/>
											<xsl:if test="exists(pages/text())">
												<xsl:text>, </xsl:text>
											</xsl:if>
										</xsl:when>
									</xsl:choose>
									<xsl:choose>
										<xsl:when test="not(exists(volume/text()) and exists(number/text())) and exists(pages/text())">
											<xsl:value-of select="concat('pp. ', pages/text())"/>
										</xsl:when>
										<xsl:when test="exists(volume/text()) and exists(number/text()) and exists(pages/text())">
											<xsl:value-of select="concat(':', pages/text())"/>
										</xsl:when>
									</xsl:choose>
								</span>
							</xsl:if>
							<xsl:for-each select="date[exists(text() | @value)]">
								<xsl:text>, </xsl:text>
								<span title="Date" class="date">
									<xsl:choose>
										<xsl:when test="exists(text())">
											<xsl:value-of select="."/>
										</xsl:when>
										<xsl:otherwise>
											<xsl:if test="(@value castable as xs:gYearMonth) or (@value castable as xs:date)">
												<xsl:variable name="month" select="number(substring(@value, 6, 2))"/>
												<xsl:choose>
													<xsl:when test="$month eq 1">January </xsl:when>
													<xsl:when test="$month eq 2">February </xsl:when>
													<xsl:when test="$month eq 3">March </xsl:when>
													<xsl:when test="$month eq 4">April </xsl:when>
													<xsl:when test="$month eq 5">May </xsl:when>
													<xsl:when test="$month eq 6">June </xsl:when>
													<xsl:when test="$month eq 7">July </xsl:when>
													<xsl:when test="$month eq 8">August </xsl:when>
													<xsl:when test="$month eq 9">September </xsl:when>
													<xsl:when test="$month eq 10">October </xsl:when>
													<xsl:when test="$month eq 11">November </xsl:when>
													<xsl:when test="$month eq 12">December </xsl:when>
												</xsl:choose>
											</xsl:if>
											<xsl:if test="@value castable as xs:date">
												<xsl:value-of select="concat(day-from-date(@value cast as xs:date),', ')"/>
											</xsl:if>
											<xsl:value-of select="substring(@value, 1, 4)"/>
										</xsl:otherwise>
									</xsl:choose>
								</span>
							</xsl:for-each>
							<xsl:for-each select="identifier[@type eq 'sharef:isbn']">
								<xsl:text>, </xsl:text>
								<span title="ISBN" class="isbn">
									<xsl:text>ISBN </xsl:text>
									<xsl:value-of select="."/>
								</span>
							</xsl:for-each>
							<xsl:for-each select="identifier[@type eq 'sharef:issn']">
								<xsl:text>, </xsl:text>
								<span title="ISSN" class="issn">
									<xsl:text>ISSN </xsl:text>
									<xsl:value-of select="."/>
								</span>
							</xsl:for-each>
							<xsl:if test="@crossref">
								<xsl:text>, </xsl:text>
								<sharef:crossref id="{@crossref}"/>
							</xsl:if>
						</sharef:text>
						<xsl:if test="$abstract ne 'no'">
							<xsl:for-each select="abstract">
								<sharef:abstract xmlns="http://www.w3.org/1999/xhtml">
									<div title="Abstract" class="abstract">
										<b>Abstract: </b>
										<xsl:call-template name="process_rich_text"/>
									</div>
								</sharef:abstract>
							</xsl:for-each>
						</xsl:if>
						<xsl:if test="$annotation ne 'no'">
							<xsl:for-each select="annotation">
								<sharef:annotation xmlns="http://www.w3.org/1999/xhtml">
									<div title="Annotation" class="annotation">
										<b>Annotation: </b>
										<xsl:call-template name="process_rich_text"/>
									</div>
								</sharef:annotation>
							</xsl:for-each>
							<xsl:for-each select="$shadow/annotation">
								<sharef:shadow-annotation xmlns="http://www.w3.org/1999/xhtml">
									<div title="Annotation" class="annotation">
										<b>Annotation: </b>
										<xsl:call-template name="process_rich_text"/>
									</div>
								</sharef:shadow-annotation>
							</xsl:for-each>
							<xsl:for-each select="if ( self::reference ) then . else key('referencekey', @target)">
								<!-- this changes the context to the shadow target, if the current entry is a shadow. -->
								<xsl:variable name="ref-id" select="generate-id()"/>
								<!-- this resets the ref-id variable to the new context (which has changed in case of the current entry being a shadow). -->
								<xsl:variable name="associations" select="associations/xref[exists(key('referencekey-nohelper', @target))][exists(key('associationkey', @type))] | key('associatedkey', $unique-ref-name)[generate-id(ancestor::reference | ancestor::shadow) ne generate-id(current())]"/>
								<!-- this variable holds all associations in which the current entry participates (both as a source and as a target) -->
								<xsl:if test="exists($associations)">
									<sharef:associations xmlns="http://www.w3.org/1999/xhtml">
										<div title="Associations" class="associations">
											<b>Associations with other References: </b>
											<xsl:for-each-group select="$associations" group-by="@type">
												<!-- associations are first grouped by type ... -->
												<xsl:for-each-group select="current-group()" group-by="if ( generate-id(ancestor::reference | ancestor::shadow) eq $ref-id ) then if ( exists(@direction) ) then @direction else 'forward' else if ( @direction eq 'reverse') then 'forward' else 'reverse'">
													<!-- ... and then by direction which needs to be reversed for xrefs from outside the entry ('forward' is the default value) -->
													<xsl:sort select="current-grouping-key()"/>
													<xsl:choose>
														<xsl:when test="$associationindex">
															<a href="associations{$linksuffix}#{@type}" title="go to association index">
																<xsl:value-of select="key('associationkey', @type)/*[local-name() eq current-grouping-key()]/text()"/>
															</a>
														</xsl:when>
														<xsl:otherwise>
															<!-- if there is no association index, just insert the text without creating a link -->
															<xsl:value-of select="key('associationkey', @type)/*[local-name() eq current-grouping-key()]/text()"/>
														</xsl:otherwise>
													</xsl:choose>
													<xsl:text>: </xsl:text>
													<xsl:for-each select="current-group()">
														<!-- the target is either the target of the xref (if the xref was in the entry) or the @id of the entry within which the xref appeared (if the xref was outside of the entry) -->
														<sharef:xref type="{@type}" target="{if ( generate-id(ancestor::reference | ancestor::shadow) eq $ref-id ) then @target else generate-id(ancestor::reference | ancestor::shadow)}" direction="{current-grouping-key()}"/>
														<xsl:if test="position() ne last()">
															<xsl:text>, </xsl:text>
														</xsl:if>
													</xsl:for-each>
													<xsl:if test="position() ne last()">
														<xsl:text>; </xsl:text>
													</xsl:if>
												</xsl:for-each-group>
												<xsl:if test="position() ne last()">
													<xsl:text>; </xsl:text>
												</xsl:if>
											</xsl:for-each-group>
										</div>
									</sharef:associations>
								</xsl:if>
							</xsl:for-each>
						</xsl:if>
						<xsl:for-each select="identifier[@type eq 'sharef:uri'] | identifier[(@type eq 'sharef:doi') and ($DOI-param ne '')] | identifier[@type eq 'sharef:isbn' and ($ISBN-param ne '')]">
							<resource type="{upper-case(substring-after(@type,'sharef:'))}" value="{.}"/>
						</xsl:for-each>
					</xsl:for-each>
				</ref>
			</xsl:for-each>
		</refs>
	</xsl:variable>
	<xsl:template name="process_names">
		<xsl:param name="node"/>
		<xsl:param name="index" select="'no'"/>
		<xsl:for-each select="$node/*">
			<xsl:variable name="name">
				<xsl:choose>
					<xsl:when test="local-name() eq 'person'">
						<xsl:value-of select="givenname"/>
						<xsl:text> </xsl:text>
						<xsl:if test="exists(surname/@link)">
							<xsl:value-of select="surname/@link"/>
							<xsl:text> </xsl:text>
						</xsl:if>
						<xsl:value-of select="surname"/>
						<xsl:if test="exists(surname/@lineage)">
							<xsl:text>, </xsl:text>
							<xsl:value-of select="surname/@lineage"/>
						</xsl:if>
					</xsl:when>
					<xsl:otherwise>
						<!-- it is a 'name', not a 'person' -->
						<xsl:value-of select="text()"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>
			<xsl:variable name="sortname">
				<xsl:choose>
					<xsl:when test="local-name() eq 'person'">
						<xsl:value-of select="surname"/>
						<xsl:if test="surname/@lineage">
							<xsl:text>, </xsl:text>
							<xsl:value-of select="surname/@lineage"/>
						</xsl:if>
						<xsl:if test="givenname">
							<xsl:text>, </xsl:text>
						</xsl:if>
						<xsl:value-of select="givenname"/>
						<xsl:if test="surname/@link">
							<xsl:text> </xsl:text>
							<xsl:value-of select="surname/@link"/>
						</xsl:if>
					</xsl:when>
					<xsl:otherwise>
						<!-- it is a 'name', not a 'person' -->
						<xsl:value-of select="text()"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>
			<span class="person">
				<xsl:if test="$index eq 'yes'">
					<xsl:attribute name="key" select="$sortname"/>
				</xsl:if>
				<xsl:choose>
					<xsl:when test="$AuthorIndex and ($index eq 'yes')">
						<a title="Author Index: {$name}" href="{$linkbase-param}{ if ( $refpage eq 'refpages' ) then '../' else '' }{concat('authors', $linksuffix, '#', translate(normalize-space($name), &quot;&apos; &quot;, ''))}">
							<xsl:value-of select="$name"/>
						</a>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="$name"/>
					</xsl:otherwise>
				</xsl:choose>
			</span>
			<xsl:if test="following-sibling::*">
				<xsl:text>, </xsl:text>
			</xsl:if>
		</xsl:for-each>
	</xsl:template>
	<xsl:variable name="reflist">
		<refs xmlns="http://dret.net/xmlns/sharef">
			<xsl:variable name="iteration" select="$reflist_nocross/refs/ref"/>
			<xsl:variable name="number" select="count($iteration)"/>
			<xsl:for-each select="$iteration">
				<xsl:if test="ceiling($percentage * (position() div $number)) != ceiling($percentage * ((position()-1) div $number))">
					<xsl:call-template name="message">
						<xsl:with-param name="level" select="'progress'"/>
						<xsl:with-param name="text" select="ceiling($percentage * (position() div $number) + $percentage)"/>
					</xsl:call-template>
				</xsl:if>
				<xsl:apply-templates mode="resolve_crossrefs" select="."/>
			</xsl:for-each>
		</refs>
	</xsl:variable>
	<xsl:template mode="resolve_crossrefs" match="@* | node()">
		<xsl:copy>
			<xsl:apply-templates mode="resolve_crossrefs" select="@* | node()"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template mode="resolve_crossrefs" match="crossref">
		<span class="crossref">
			<xsl:text> In: </xsl:text>
			<a title="go to reference" href="{ if ( $refpage eq 'refpages' ) then '' else '#' }{@id}{ if ( $refpage eq 'refpages' ) then $linksuffix else '' }">
				<xsl:apply-templates select="key('refkey', @id, $reflist_nocross)/text" mode="crossref"/>
			</a>
		</span>
	</xsl:template>
	<xsl:template mode="resolve_crossrefs" match="associations">
		<xsl:choose>
			<xsl:when test="$refpage eq 'listonly'">
				<!-- if no individual reference pages are generated, the simple html layout can be retained -->
				<xsl:copy>
					<xsl:apply-templates mode="resolve_crossrefs" select="@* | node()"/>
				</xsl:copy>
			</xsl:when>
			<xsl:otherwise>
				<!-- if individual reference pages are generated, it is necessary to generate the more complex table-oriented layout -->
				<sharef:associations>
					<table rules="all" border="1" class="associations-table" cellpadding="2">
						<tbody>
							<xsl:for-each-group select=".//xref" group-by="@type">
								<xsl:sort select="@direction"/>
								<tr>
									<td align="right" valign="top" rowspan="{count(distinct-values(current-group()/@direction))}">
										<b>
											<xsl:choose>
												<xsl:when test="$associationindex">
													<a href="../associations{$linksuffix}#{@type}" title="go to association index">
														<xsl:value-of select="key('associationkey', current-grouping-key(), $document)/association/text()"/>
													</a>
												</xsl:when>
												<xsl:otherwise>
													<!-- if there is no association index, just insert the text without creating a link -->
													<xsl:value-of select="key('associationkey', current-grouping-key(), $document)/association/text()"/>
												</xsl:otherwise>
											</xsl:choose>
											<xsl:text>:</xsl:text>
										</b>
									</td>
									<xsl:call-template name="list-refs">
										<!-- process first direction of the associations -->
										<xsl:with-param name="part" select="'head'"/>
									</xsl:call-template>
								</tr>
								<xsl:if test="count(distinct-values(current-group()/@direction)) gt 1">
									<tr>
										<xsl:call-template name="list-refs">
											<!-- process second direction of the associations -->
											<xsl:with-param name="part" select="'tail'"/>
										</xsl:call-template>
									</tr>
								</xsl:if>
							</xsl:for-each-group>
						</tbody>
					</table>
				</sharef:associations>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template mode="resolve_crossrefs" match="xref">
		<xsl:variable name="target" select="if ( exists(key('generatedidkey', @target, $reflist_nocross)) ) then key('generatedidkey', @target, $reflist_nocross)/@id else @target"/>
		<span class="id">
			<a href="#{$target}">
				<xsl:attribute name="title"><xsl:apply-templates select="key('refkey', $target, $reflist_nocross)/text" mode="crossref"/></xsl:attribute>
				<xsl:value-of select="$target"/>
			</a>
		</span>
	</xsl:template>
	<xsl:template match="html:span | @* " mode="crossref">
		<!-- this template only copies the html elements which are required in the crossref text -->
		<xsl:copy>
			<xsl:apply-templates select="@class | node()" mode="crossref"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="html:* | @* " mode="remove-key">
		<!-- this template only copies the html elements which are required in the reference text, it removes html:span/@key -->
		<xsl:copy>
			<xsl:apply-templates select="@class | @title | @href | node()" mode="remove-key"/>
		</xsl:copy>
	</xsl:template>
	<xsl:template match="/">
		<xsl:result-document href="{$html_dir}{$cssname}" method="text">
			<xsl:value-of xpath-default-namespace="" select="$parameters//css"/>
		</xsl:result-document>
		<xsl:result-document href="{$html_dir}references{$filesuffix}" format="xhtml" encoding="{$html_encoding}">
			<html>
				<head>
					<title>Reference List</title>
					<xsl:call-template name="generate_headers"/>
				</head>
				<body>
					<h1>Reference List</h1>
					<xsl:if test="$AuthorIndex or $TitleIndex or $keywordindex or $associationindex">
						<!-- only display the following title if at least one index is generated -->
						<h3>
							<xsl:text>(Also accessible through the following Indices: </xsl:text>
							<xsl:if test="$AuthorIndex">
								<a href="authors{$linksuffix}" title="go to author index">Author</a>
								<xsl:if test="$TitleIndex or $keywordindex or $associationindex">
									<xsl:text>; </xsl:text>
								</xsl:if>
							</xsl:if>
							<xsl:if test="$TitleIndex">
								<a href="{$linkbase-param}titles{$linksuffix}" title="go to title index">Title</a>
								<xsl:if test="$keywordindex or $associationindex">
									<xsl:text>; </xsl:text>
								</xsl:if>
							</xsl:if>
							<xsl:if test="$keywordindex">
								<a href="{$linkbase-param}keywords{$linksuffix}" title="go to keyword index">Keyword</a>
								<xsl:if test="$associationindex">
									<xsl:text>; </xsl:text>
								</xsl:if>
							</xsl:if>
							<xsl:if test="$associationindex">
								<a href="{$linkbase-param}associations{$linksuffix}" title="go to association index">Association</a>
							</xsl:if>
							<xsl:text>)</xsl:text>
						</h3>
					</xsl:if>
					<hr/>
					<table rules="rows" border="1" cellpadding="3" cellspacing="1">
						<thead>
							<tr>
								<xsl:if test="$showid">
									<th align="center">Reference&#xA0;Name</th>
								</xsl:if>
								<th align="center">Reference&#xA0;Text</th>
								<xsl:if test="(exists($reflist//resource) or $OpenURL-param or ($DOI-param ne '') or ($ISBN-param ne '') or ($google ne 'no')) and ($refpage eq 'listonly')">
									<!-- only render the resource column if there will be content and if no individual refpages are generated -->
									<th align="center">Resource(s)</th>
								</xsl:if>
							</tr>
						</thead>
						<tbody>
							<xsl:variable name="iteration" select="$reflist/refs/ref[not(string(@helper) eq 'true')]"/>
							<xsl:variable name="number" select="count($iteration)"/>
							<xsl:for-each select="$iteration">
								<!-- the sort keys have been generated in the first pass in the $reflist_nocross variable -->
								<xsl:sort select="@key1" order="{ if ($htmlsort1 eq 'date-desc') then 'descending' else 'ascending' }"/>
								<xsl:sort select="@key2" order="{ if ($htmlsort2 eq 'date-desc') then 'descending' else 'ascending' }"/>
								<xsl:if test="ceiling($percentage * (position() div $number)) != ceiling($percentage * ((position()-1) div $number))">
									<xsl:call-template name="message">
										<xsl:with-param name="level" select="'progress'"/>
										<xsl:with-param name="text" select="ceiling($percentage * (position() div $number) + (2 * $percentage))"/>
									</xsl:call-template>
								</xsl:if>
								<tr id="{@id}" title="{concat(upper-case(substring(@class, 1, 1)), substring(@class, 2))}">
									<xsl:if test="$showid">
										<td valign="top">
											<xsl:if test="exists(@name)">
												<span class="id">
													<xsl:value-of select="@name"/>
												</span>
											</xsl:if>
										</td>
									</xsl:if>
									<td valign="top">
										<div class="{@class}">
											<xsl:choose>
												<xsl:when test="$refpage eq 'listonly'">
													<!-- this makes sure that shadows and references are displayed differently through css classes -->
													<xsl:apply-templates select="text/node()" mode="remove-key"/>
													<xsl:text>.</xsl:text>
													<xsl:if test="abstract">
														<xsl:copy-of select="abstract/node()"/>
													</xsl:if>
													<xsl:if test="annotation">
														<xsl:copy-of select="annotation/node()"/>
													</xsl:if>
													<xsl:if test="associations">
														<xsl:copy-of select="associations/node()"/>
													</xsl:if>
												</xsl:when>
												<xsl:otherwise>
													<!-- this part is executed when it is necessary to create individual pages for all references ($refpage eq 'refpages') -->
													<xsl:variable name="reftext">
														<xsl:apply-templates select="text/node()" mode="remove-key"/>
													</xsl:variable>
													<a href="reference/{@id}{$linksuffix}" title="go to details page">
														<xsl:apply-templates mode="crossref" select="$reftext"/>
													</a>
													<xsl:result-document href="{$html_dir}reference/{@id}{$filesuffix}" format="xhtml" encoding="{$html_encoding}">
														<html>
															<head>
																<title>
																	<xsl:value-of select="string(text/html:span[@class eq 'title'][1])"/>
																	<xsl:if test="exists(text/html:span[@class = ('author', 'editor')])">
																		<xsl:value-of select="' [', text/html:span[@class = ('author', 'editor')][1], ']'"/>
																	</xsl:if>
																</title>
																<xsl:call-template name="generate_headers">
																	<xsl:with-param name="location-prefix" select="'../'"/>
																</xsl:call-template>
																<xsl:if test="$drettest">
																	<xsl:copy-of select="$dretbiblio/dretbiblio/htmlheadscript/*"/>
																</xsl:if>
															</head>
															<body>
																<xsl:if test="$drettest">
																	<xsl:copy-of select="$dretbiblio/dretbiblio/htmladscript/*"/>
																</xsl:if>
																<h1>
																	<xsl:value-of select="string(text/html:span[@class eq 'title'][1])"/>
																</h1>
																<xsl:if test="text/html:span[@class eq 'author']">
																	<h2>
																		<xsl:copy-of select="text/html:span[@class eq 'author']"/>
																	</h2>
																</xsl:if>
																<table rules="all" border="1" cellpadding="3" cellspacing="1">
																	<tbody>
																		<xsl:if test="exists(@name) or (exists(@shadow) and (exists(key('referencename', @shadow, $document))))"/>
																		<tr>
																			<th align="right" valign="top" class="leftcolumn">Identifier</th>
																			<td class="rightcolumn">
																				<xsl:if test="exists(@name)">
																					<span class="id">
																						<xsl:value-of select="@name"/>
																					</span>
																					<xsl:text> </xsl:text>
																				</xsl:if>
																				<xsl:if test="exists(@shadow)">
																					<xsl:variable name="shadow-text">
																						<span class="{@class}">
																							<xsl:text>(This is a shadow</xsl:text>
																							<xsl:if test="exists(key('referencename', @shadow, $document)/@name)">
																								<xsl:text> of </xsl:text>
																								<span class="id">
																									<xsl:value-of select="@shadow"/>
																								</span>
																							</xsl:if>
																							<xsl:text>)</xsl:text>
																						</span>
																					</xsl:variable>
																					<xsl:choose>
																						<xsl:when test="exists(key('referencename', @shadow, $document))">
																							<!-- create a link if the shadow source exists -->
																							<a href="{@shadow}{$linksuffix}">
																								<xsl:copy-of select="$shadow-text"/>
																							</a>
																						</xsl:when>
																						<xsl:otherwise>
																							<!-- just display the text (no link) if the shadow source does not exist -->
																							<xsl:copy-of select="$shadow-text"/>
																						</xsl:otherwise>
																					</xsl:choose>
																				</xsl:if>
																			</td>
																		</tr>
																		<xsl:if test="starts-with(type/text(), 'sharef:')">
																			<tr>
																				<th align="right" valign="top" class="leftcolumn">Type</th>
																				<td class="rightcolumn">
																					<xsl:value-of select="concat(upper-case(substring(substring-after(type/text(), 'sharef:'), 1, 1)), substring(substring-after(type/text(), 'sharef:'), 2))"/>
																				</td>
																			</tr>
																		</xsl:if>
																		<tr>
																			<th align="right" valign="top" class="leftcolumn">Citation</th>
																			<td class="rightcolumn">
																				<div class="{@class}">
																					<xsl:apply-templates select="text/node()" mode="remove-key"/>
																					<xsl:text>.</xsl:text>
																				</div>
																			</td>
																		</tr>
																		<xsl:if test="exists(abstract | annotation)">
																			<tr>
																				<th align="right" valign="top" class="leftcolumn">Descriptions</th>
																				<td class="rightcolumn">
																					<div class="{@class}">
																						<xsl:if test="exists(abstract)">
																							<xsl:copy-of select="abstract/node()"/>
																						</xsl:if>
																						<xsl:if test="exists(annotation)">
																							<xsl:copy-of select="annotation/node()"/>
																						</xsl:if>
																					</div>
																				</td>
																			</tr>
																		</xsl:if>
																		<xsl:if test="exists(key('crossrefkey', @id, $document))">
																			<tr>
																				<th align="right" valign="top" class="leftcolumn">Cross References</th>
																				<td class="rightcolumn">
																					<ul>
																						<xsl:for-each select="key('crossrefkey', @id, $document)">
																							<li>
																								<xsl:variable name="id" select="if ( exists(@name) ) then @name else sharef:generate-ref-name(string(names[@type eq 'sharef:author'][1]/(name | person/surname)[1]), string(date/@value))"/>
																								<xsl:variable name="reftext">
																									<xsl:apply-templates select="key('refkey', $id, $reflist)/text/node()" mode="remove-key"/>
																								</xsl:variable>
																								<a href="{$id}{$linksuffix}" title="go to details page">
																									<xsl:apply-templates mode="crossref" select="$reftext"/>
																								</a>
																								<xsl:text>.</xsl:text>
																							</li>
																						</xsl:for-each>
																					</ul>
																				</td>
																			</tr>
																		</xsl:if>
																		<xsl:if test="exists(associations)">
																			<tr>
																				<th align="right" valign="top" class="leftcolumn">Associations</th>
																				<td class="rightcolumn">
																					<xsl:copy-of select="associations"/>
																				</td>
																			</tr>
																		</xsl:if>
																		<xsl:if test="exists(resource) or $OpenURL-param or ($DOI-param ne '') or ($ISBN-param ne '') or ($google ne 'no')">
																			<tr>
																				<th align="right" valign="top" class="leftcolumn">Resources</th>
																				<td class="rightcolumn">
																					<div class="{@class}">
																						<table rules="none" class="resource">
																							<tbody>
																								<xsl:for-each select="resource, if ($OpenURL-param and openurl) then openurl else (), if ($google ne 'no') then . else ()">
																									<xsl:sort select="if ( exists(self::ref) ) then 'google' else if ( exists(self::openurl) ) then 'openurl' else lower-case(@type)"/>
																									<tr>
																										<td align="right" valign="top">
																											<xsl:choose>
																												<xsl:when test="exists(self::ref)">
																													<b>Google: </b>
																												</xsl:when>
																												<xsl:when test="@type eq 'URI'">
																													<b>URI: </b>
																												</xsl:when>
																												<xsl:when test="@type eq 'DOI'">
																													<b>DOI: </b>
																												</xsl:when>
																												<xsl:when test="@type eq 'ISBN'">
																													<b>ISBN: </b>
																												</xsl:when>
																												<xsl:when test="exists(self::openurl)">
																													<b>OpenURL: </b>
																												</xsl:when>
																											</xsl:choose>
																										</td>
																										<td>
																											<xsl:choose>
																												<xsl:when test="exists(self::ref)">
																													<xsl:variable name="querystring">
																														<!-- take the title part -->
																														<xsl:value-of select="concat('&quot;', normalize-space(string(text/html:span[@class eq 'title'][1])), '&quot;')"/>
																														<xsl:if test="($google eq 'titleauthor') and exists(text/html:span[@class eq 'author'][1])">
																															<xsl:text>+</xsl:text>
																															<!-- take the normalized first author part, replace spaces with +, remove commas -->
																															<xsl:value-of select="translate(normalize-space(string(text/html:span[@class='author'][1])), ' ,', '+')"/>
																														</xsl:if>
																													</xsl:variable>
																													<a title="search with Google" href="{concat('http://www.google.com/search?q=', escape-html-uri($querystring))}">
																														<xsl:text>Search for </xsl:text>
																														<code>
																															<!-- if the query string is not broken that way, it will cause very long lines (for entries with many authors/editos) which mess up the display of the table -->
																															<xsl:value-of select="concat('[', translate($querystring, '+', ' '), ']')"/>
																														</code>
																													</a>
																												</xsl:when>
																												<xsl:when test="@type eq 'URI'">
																													<code>
																														<a href="{@value}">
																															<xsl:value-of select="@value"/>
																														</a>
																													</code>
																												</xsl:when>
																												<xsl:when test="@type eq 'DOI'">
																													<code>
																														<a href="{concat($DOI-param, @value)}" title="look up DOI">
																															<xsl:value-of select="@value"/>
																														</a>
																													</code>
																												</xsl:when>
																												<xsl:when test="@type eq 'ISBN'">
																													<code>
																														<a href="{concat($ISBN-param, translate(@value,'- ',''))}" title="look up ISBN">
																															<xsl:value-of select="@value"/>
																														</a>
																													</code>
																												</xsl:when>
																												<xsl:when test="exists(self::openurl)">
																													<xsl:text>Query resolver </xsl:text>
																													<code>
																														<a href="{concat($OpenURL-param, '?', text())}" title="look up reference at OpenURL resolver {$OpenURL-param}">
																															<xsl:value-of select="$OpenURL-param"/>
																														</a>
																													</code>
																												</xsl:when>
																											</xsl:choose>
																										</td>
																									</tr>
																								</xsl:for-each>
																							</tbody>
																						</table>
																					</div>
																				</td>
																			</tr>
																		</xsl:if>
																		<xsl:if test="exists(shadow-annotation)">
																			<tr>
																				<th align="right" valign="top" class="leftcolumn">Shadow Annotations</th>
																				<td class="rightcolumn">
																					<xsl:copy-of select="shadow-annotation/node()"/>
																				</td>
																			</tr>
																		</xsl:if>
																		<tr>
																		</tr>
																	</tbody>
																</table>
																<p>

																	<b>Bibliography Navigation: </b>
																			<a href="../references{$linksuffix}#{@id}">Reference List</a>
																			<xsl:if test="$AuthorIndex">
																				<xsl:text>; </xsl:text>
																				<a href="../authors{$linksuffix}">Author Index</a>
																			</xsl:if>
																			<xsl:if test="$TitleIndex">
																				<xsl:text>; </xsl:text>
																				<a href="../titles{$linksuffix}#{@id}">Title Index</a>
																			</xsl:if>
																			<xsl:if test="$keywordindex">
																				<xsl:text>; </xsl:text>
																				<a href="../keywords{$linksuffix}">Keyword Index</a>
																			</xsl:if>
																			<xsl:if test="$associationindex">
																				<xsl:text>; </xsl:text>
																				<a href="../associations{$linksuffix}#{@id}">Association Index</a>
																			</xsl:if>
																</p>
																<xsl:copy-of select="$footer"/>
															</body>
														</html>
													</xsl:result-document>
												</xsl:otherwise>
											</xsl:choose>
										</div>
										<xsl:if test="exists(shadow-annotation) and ($reflist eq 'listonly')">
											<xsl:copy-of select="shadow-annotation/node()"/>
										</xsl:if>
									</td>
									<xsl:if test="(exists(resource) or $OpenURL-param or $DOI-param or $ISBN-param or ($google ne 'no')) and ($refpage eq 'listonly')">
										<td valign="top">
											<xsl:for-each select="resource">
												<xsl:sort select="@type"/>
												<span class="resource">
													<a>
														<xsl:choose>
															<xsl:when test="@type eq 'URI'">
																<xsl:attribute name="title">go to <xsl:value-of select="@value"/></xsl:attribute>
																<xsl:attribute name="href"><xsl:value-of select="@value"/></xsl:attribute>
																<xsl:text>&#x2192;&#xA0;URI</xsl:text>
															</xsl:when>
															<xsl:when test="(@type eq 'DOI') and ($DOI-param ne '')">
																<xsl:attribute name="title">DOI: <xsl:value-of select="@value"/></xsl:attribute>
																<xsl:attribute name="href"><xsl:value-of select="concat($DOI-param,@value)"/></xsl:attribute>
																<xsl:text>&#x2192;&#xA0;DOI</xsl:text>
															</xsl:when>
															<xsl:when test="(@type eq 'ISBN') and $ISBN-param">
																<xsl:attribute name="title">ISBN: <xsl:value-of select="@value"/></xsl:attribute>
																<!-- translate() removes '-' and ' ' from the ISBN number -->
																<xsl:attribute name="href"><xsl:value-of select="concat($ISBN-param,translate(@value,'- ',''))"/></xsl:attribute>
																<xsl:text>&#x2192;&#xA0;ISBN</xsl:text>
															</xsl:when>
														</xsl:choose>
													</a>
												</span>
												<xsl:text> </xsl:text>
											</xsl:for-each>
											<xsl:if test="$OpenURL-param and openurl">
												<xsl:text> </xsl:text>
												<span class="resource">
													<a title="look up reference at OpenURL resolver {$OpenURL-param}" href="{concat($OpenURL-param, '?', openurl)}">
														<xsl:text>&#x2192;&#xA0;Library</xsl:text>
													</a>
												</span>
											</xsl:if>
											<xsl:if test="$google ne 'no'">
												<xsl:text> </xsl:text>
												<span class="resource">
													<xsl:variable name="querystring">
														<!-- take the title part -->
														<xsl:value-of select="concat('&quot;', normalize-space(string(text/html:span[@class='title'][1])), '&quot;')"/>
														<xsl:if test="($google eq 'titleauthor') and exists(text/html:span[@class='author'][1])">
															<xsl:text>+</xsl:text>
															<!-- take the normalized first author part, replace spaces with +, remove commas -->
															<xsl:value-of select="translate(normalize-space(string(text/html:span[@class='author'][1])), ' ,', '+')"/>
														</xsl:if>
													</xsl:variable>
													<a title="search with Google" href="{concat('http://www.google.com/search?q=', escape-html-uri($querystring))}">
														<xsl:text>&#x2192;&#xA0;Google</xsl:text>
													</a>
												</span>
											</xsl:if>
										</td>
									</xsl:if>
								</tr>
							</xsl:for-each>
						</tbody>
					</table>
					<xsl:copy-of select="$footer"/>
				</body>
			</html>
		</xsl:result-document>
		<xsl:if test="$AuthorIndex">
			<xsl:result-document href="{$html_dir}authors{$filesuffix}" format="xhtml" encoding="{$html_encoding}">
				<html>
					<head>
						<title>Author Index</title>
						<xsl:call-template name="generate_headers"/>
					</head>
					<body>
						<h1>Author Index</h1>
						<h3>Authors of the <a href="{$linkbase-param}references{$linksuffix}">Reference List</a>
						</h3>
						<hr/>
						<ul>
							<xsl:variable name="iteration" select="$reflist//html:span[@class eq 'person'][exists(@key)]"/>
							<xsl:variable name="number" select="count($iteration)"/>
							<xsl:for-each-group select="$iteration" group-by="translate(@key,&quot;&apos;., &quot;,'')">
								<xsl:sort select="current-grouping-key()"/>
								<xsl:if test="ceiling($percentage * (position() div $number)) != ceiling($percentage * ((position()-1) div $number))">
									<xsl:call-template name="message">
										<xsl:with-param name="level" select="'progress'"/>
										<xsl:with-param name="text" select="ceiling($percentage * (position() div $number) + (3 * $percentage))"/>
									</xsl:call-template>
								</xsl:if>
								<li id="{translate(.,&quot;&apos; &quot;,'')}">
									<xsl:value-of select="@key"/>
									<xsl:text>: </xsl:text>
									<xsl:for-each select="current-group()/ancestor::ref">
										<!-- sort by name, if present, otherwise by title -->
										<xsl:sort select="@id"/>
										<xsl:if test="position() > 1">
											<xsl:text>, </xsl:text>
										</xsl:if>
										<a href="{$linkbase-param}reference{ if ( $refpage eq 'refpages' ) then '/' else concat('s', $linksuffix, '#') }{@id}{ if ( $refpage eq 'refpages' ) then $linksuffix else '' }" title="{string(text)}">
											<span class="id">
												<xsl:value-of select="if ( exists(@name) ) then @name else @gen-id"/>
											</span>
										</a>
									</xsl:for-each>
								</li>
							</xsl:for-each-group>
						</ul>
						<xsl:copy-of select="$footer"/>
					</body>
				</html>
			</xsl:result-document>
		</xsl:if>
		<xsl:if test="$TitleIndex">
			<xsl:result-document href="{$html_dir}titles{$filesuffix}" format="xhtml" encoding="{$html_encoding}">
				<html>
					<head>
						<title>Title Index</title>
						<xsl:call-template name="generate_headers"/>
					</head>
					<body>
						<h1>Title Index</h1>
						<h3>Titles of all Entries of the <a href="{$linkbase-param}references{$linksuffix}">Reference List</a>
						</h3>
						<hr/>
						<ol>
							<xsl:variable name="iteration" select="$reflist/refs/ref"/>
							<xsl:variable name="number" select="count($iteration)"/>
							<xsl:for-each select="$iteration">
								<xsl:sort select="text/html:span[@class eq 'title']"/>
								<xsl:if test="ceiling($percentage * (position() div $number)) != ceiling($percentage * ((position()-1) div $number))">
									<xsl:call-template name="message">
										<xsl:with-param name="level" select="'progress'"/>
										<xsl:with-param name="text" select="ceiling($percentage * (position() div $number) + ((3 + number($AuthorIndex)) * $percentage))"/>
									</xsl:call-template>
								</xsl:if>
								<li id="{@id}">
									<span class="title">
										<a title="{string(text)}" href="{$linkbase-param}reference{ if ( $refpage eq 'refpages' ) then '/' else concat('s', $linksuffix, '#') }{@id}{ if ( $refpage eq 'refpages' ) then $linksuffix else '' }">
											<xsl:value-of select="text/html:span[@class eq 'title']"/>
										</a>
									</span>
								</li>
							</xsl:for-each>
						</ol>
						<xsl:copy-of select="$footer"/>
					</body>
				</html>
			</xsl:result-document>
		</xsl:if>
		<xsl:if test="$keywordindex">
			<xsl:result-document href="{$html_dir}keywords{$filesuffix}" format="xhtml" encoding="{$html_encoding}">
				<html>
					<head>
						<title>Keyword Index</title>
						<xsl:call-template name="generate_headers"/>
					</head>
					<body>
						<h1>Keyword Index</h1>
						<h3>All Keywords of the <a href="{$linkbase-param}references{$linksuffix}">Reference List</a>
						</h3>
						<hr/>
						<ol>
							<xsl:variable name="iteration" select="$document/bibliography/keyworddef[exists(key('referencekeywordkey', @id))]"/>
							<xsl:variable name="number" select="count($iteration)"/>
							<xsl:for-each select="$iteration">
								<xsl:sort select="keyword/text()"/>
								<xsl:if test="ceiling($percentage * (position() div $number)) != ceiling($percentage * ((position()-1) div $number))">
									<xsl:call-template name="message">
										<xsl:with-param name="level" select="'progress'"/>
										<xsl:with-param name="text" select="ceiling($percentage * (position() div $number) + ((3 + number($AuthorIndex) + number($TitleIndex)) * $percentage))"/>
									</xsl:call-template>
								</xsl:if>
								<li id="{@id}">
									<span class="keyword">
												<xsl:value-of select="concat(keyword/text(), if ( exists(alias) ) then concat(' (', alias/text(), ')') else '')"/>
									</span>
									<xsl:text>: </xsl:text>
									<xsl:variable name="keywordid" select="string(@id)"/>
									<xsl:for-each select="key('referencekeywordkey', $keywordid)">
										<!-- sorting uses the keywordref with the highest @weight (there may be more than one per reference) -->
										<xsl:sort data-type="number" order="descending" select="max(for $i in .//keywordref[@type eq $keywordid]  return if ( exists($i/@weight) ) then number($i/@weight) else '1' )"/>
										<xsl:variable name="newid" select="key('generatedidkey', generate-id(.), $reflist)/@id"/>
										<xsl:if test="position() > 1">
											<xsl:text>, </xsl:text>
										</xsl:if>
										<a href="{$linkbase-param}reference{ if ( $refpage eq 'refpages' ) then '/' else concat('s', $linksuffix, '#') }{$newid}{ if ( $refpage eq 'refpages' ) then $linksuffix else '' }" title="{string(key('refkey', $newid, $reflist)/text)}">
											<span class="id">
												<xsl:value-of select="$newid"/>
											</span>
											<xsl:variable name="maxweight" select="number(max(for $i in .//keywordref[@type eq $keywordid]  return if ( exists($i/@weight) ) then number($i/@weight) else '1' ))"/>
											<xsl:if test="$maxweight lt 1">
												<!-- display the highest @weight of a keywordref within a reference if it is less than one -->
												<span class="weight">
													<sub>
														<xsl:value-of select="$maxweight"/>
													</sub>
												</span>
											</xsl:if>
										</a>
									</xsl:for-each>
								</li>
							</xsl:for-each>
						</ol>
						<xsl:copy-of select="$footer"/>
					</body>
				</html>
			</xsl:result-document>
		</xsl:if>
		<xsl:if test="$associationindex">
			<xsl:result-document href="{$html_dir}associations{$filesuffix}" format="xhtml" encoding="{$html_encoding}">
				<html>
					<head>
						<title>Association Index</title>
						<xsl:call-template name="generate_headers"/>
					</head>
					<body>
						<h1>Association Index</h1>
						<h3>All Associations of the <a href="{$linkbase-param}references{$linksuffix}">Reference List</a>
						</h3>
						<hr/>
						<ol>
							<xsl:variable name="visible-xrefs" select="//xref[exists((ancestor::reference | ancestor::shadow)[not(string(@helper) eq 'true')]) or exists(key('referencekey-nohelper', @target))]"/>
							<xsl:variable name="iteration" select="$document/bibliography/associationdef[@id = $visible-xrefs/@type]"/>
							<xsl:variable name="number" select="count($iteration)"/>
							<xsl:for-each select="$iteration">
								<xsl:sort select="association/text()"/>
								<xsl:if test="ceiling($percentage * (position() div $number)) != ceiling($percentage * ((position()-1) div $number))">
									<xsl:call-template name="message">
										<xsl:with-param name="level" select="'progress'"/>
										<xsl:with-param name="text" select="ceiling($percentage * (position() div $number) + ((3 + number($AuthorIndex) + number($TitleIndex) + number($keywordindex)) * $percentage))"/>
									</xsl:call-template>
								</xsl:if>
								<li id="{@id}">
									<span class="keyword">
										<xsl:value-of select="association/text()"/>
									</span>
									<xsl:text>: </xsl:text>
									<xsl:for-each select="key('xrefkey', @id)/(ancestor::reference | ancestor::shadow)[not(string(@helper) eq 'true')] | /bibliography/(reference | shadow)[not(string(@helper) eq 'true')][exists(key('associatedkey', key('generatedidkey', generate-id(.), $reflist)/@id)[@type eq current()/@id])]">
										<!-- this iterates over all references which either contain an xref to the current associationdef, or which are the target of an xref of the current associationdef, and all these references are sorted by id -->
										<xsl:variable name="newid" select="key('generatedidkey', generate-id(.), $reflist)/@id"/>
										<xsl:if test="position() > 1">
											<xsl:text>, </xsl:text>
										</xsl:if>
										<a href="{$linkbase-param}reference{ if ( $refpage eq 'refpages' ) then '/' else concat('s', $linksuffix, '#') }{$newid}{ if ( $refpage eq 'refpages' ) then $linksuffix else '' }" title="{string(key('refkey', $newid, $reflist)/text)}">
											<span class="id">
												<xsl:value-of select="$newid"/>
											</span>
										</a>
									</xsl:for-each>
								</li>
							</xsl:for-each>
						</ol>
						<xsl:copy-of select="$footer"/>
					</body>
				</html>
			</xsl:result-document>
		</xsl:if>
		<xsl:if test="$drettest">
			<xsl:result-document href="topicbiblio.xml" format="xml" xmlns="">
				<topicbiblio>
					<xsl:for-each select="//reference[not(string(@helper) eq 'true')][exists(.//keywordref)]">
						<entry id="{@name}" date="{date/@value}">
							<xsl:for-each select=".//keywordref">
								<topicref TID="{substring-after(@type, 'topic-')}" weight="{ if ( exists(@weight) ) then number(@weight) else '1' }"/>
							</xsl:for-each>
							<html xmlns="http://www.w3.org/1999/xhtml">
								<xsl:apply-templates select="key('generatedidkey', generate-id(.), $reflist)/text" mode="crossref"/>
							</html>
						</entry>
					</xsl:for-each>
				</topicbiblio>
			</xsl:result-document>
		</xsl:if>
		<xsl:call-template name="message">
			<xsl:with-param name="level" select="'progress'"/>
			<xsl:with-param name="text" select="'100'"/>
		</xsl:call-template>
	</xsl:template>
	<xsl:template name="generate_headers">
		<xsl:param name="location-prefix" select="''"/>
		<meta http-equiv="Content-Type" content="text/html; charset={$html_encoding}"/>
		<meta name="DC.Date" content="(SCHEME=ISO8601) {substring(string(current-date()), 1, 10)}"/>
		<!-- the weird dollar escaping ($ = &#x24;) is necessary so that the CVS does not recognize the CVS keywords -->
		<meta name="DC.Creator" content="{substring-before(substring-after($cvsid, '&#x24;Id: '), ' &#x24;')}"/>
		<link rel="stylesheet" type="text/css" href="{$location-prefix}{$cssname}"/>
	</xsl:template>
	<xsl:function name="sharef:target">
		<xsl:param name="ref"/>
		<xsl:choose>
			<xsl:when test="exists($ref/@name)">
				<xsl:value-of select="$ref/@name"/>
			</xsl:when>
			<xsl:when test="exists($ref/@id)">
				<xsl:value-of select="$ref/@id"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="generate-id($ref)"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:function>
	<xsl:template name="process_rich_text">
		<xsl:for-each select="sharef:richtext/sharef:p">
			<p>
				<xsl:apply-templates select="node()"/>
			</p>
		</xsl:for-each>
	</xsl:template>
	<xsl:template match="b | i | u | sub | sup">
		<xsl:element name="{local-name()}">
			<xsl:apply-templates select="node()"/>
		</xsl:element>
	</xsl:template>
	<xsl:template match="a">
		<a href="{@href}">
			<xsl:if test="exists(@title)">
				<xsl:attribute name="title" select="@title"/>
			</xsl:if>
			<xsl:apply-templates select="node()"/>
		</a>
	</xsl:template>
	<xsl:template match="keywordref">
		<xsl:choose>
			<xsl:when test="exists(key('keywordkey', @type))">
				<span class="keyword">
					<xsl:choose>
						<xsl:when test="$keywordindex">
							<a href="{ if ( $refpage eq 'refpages' ) then '../' else ''}keywords{$linksuffix}#{@type}" title="go to keyword index">
								<xsl:value-of select="concat(key('keywordkey', @type)/keyword/text(), if ( exists(key('keywordkey', @type)/alias) ) then concat(' (', key('keywordkey', @type)/alias/text(), ')') else '')"/>
								<xsl:if test="number(@weight) lt 1">
									<span class="weight">
										<sub>
											<xsl:value-of select="number(@weight)"/>
										</sub>
									</span>
								</xsl:if>
							</a>
						</xsl:when>
						<xsl:otherwise>
							<!-- if there is no keyword index, just insert the text without creating a link -->
							<xsl:value-of select="key('keywordkey', @type)/keyword/text()"/>
						</xsl:otherwise>
					</xsl:choose>
				</span>
			</xsl:when>
		</xsl:choose>
	</xsl:template>
	<xsl:template name="list-refs">
		<xsl:param name="part" select="'head'"/>
		<xsl:variable name="xrefs" select="current-group()[if ($part eq 'head') then ( string(@direction) eq string(current-group()[1]/@direction) ) else ( string(@direction) ne string(current-group()[1]/@direction) ) ]"/>
		<td align="right" valign="top">
			<i>
				<xsl:value-of select="key('associationkey', $xrefs[1]/@type, $document)/*[local-name() eq $xrefs[1]/@direction]/text()"/>
			</i>
		</td>
		<td>
			<ul>
				<xsl:for-each select="$xrefs">
					<xsl:variable name="target" select=" if ( exists(key('generatedidkey', @target, $reflist_nocross)) ) then key('generatedidkey', @target, $reflist_nocross)/@id else @target"/>
					<li>
						<a href="{$target}{$linksuffix}">
							<xsl:apply-templates mode="crossref" select="key('refkey', $target)/text"/>
						</a>
					</li>
				</xsl:for-each>
			</ul>
		</td>
	</xsl:template>
</xsl:stylesheet>
