<?xml version="1.0" encoding="UTF-8"?>
<!-- http://www.language-archives.org/tools/metadata/metadata.xsl
     A stylesheet for transforming free-standing OLAC metadata
       into a web page following the OLAC Display Format.
     Gary Simons, SIL International (last updated 7 June 2003)

Copyright (c) 2003 Gary Simons (SIL International). This material may be
distributed only subject to the terms and conditions set forth in the
Open Publication License, v1.0 or later (the latest version is presently
available at http://www.opencontent.org/openpub/).
 -->
 <!-- Modified by Marisa Ferrara, The LINGUIST List, 26-JUN-03 to display
 a search results page rather than a web page.
 -->
 <!--This header calls up the namespaces needed to identify the elements -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:olac="http://www.language-archives.org/OLAC/1.0/">
<xsl:output method="html" version="4.0"/>
 <!--This template establishes the TITLE variable and then the HTML display.  TITLE is called upon first as the header, and then the elements will show within the APPLY TEMPLATES area. -->
<xsl:template match="/olac:olac">
	<xsl:variable name="title">
		<xsl:choose>
			<xsl:when test="dc:title|dcterms:alternative">
				<xsl:value-of select="(dc:title|dcterms:alternative)[1]"/>
			</xsl:when>
			<xsl:otherwise>No title</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	<html>
		<head>
			<title>
				<xsl:value-of select="$title"/>
			</title>
		</head>
		<body>
			<table width="478" align="center" bgcolor="#F1F1F1">
				<tr>
					<td colspan="2">
						<span style="color: blue ; font-size:small ; font-weight:bold ; font-family:'Verdana'">
							<xsl:value-of select="$title"></xsl:value-of>
						</span>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						<xsl:apply-templates></xsl:apply-templates>
					</td>
				</tr>
			</table>
		</body>
	</html>
</xsl:template>
<!--This template establishes the variables and parameters needed for display -->
<xsl:template match="*">
  <!-- This variable parses the tag name from its namespace heading-->
	<xsl:variable name="tag">
		<xsl:choose>
			<xsl:when test="contains(name(),':')">
				<xsl:value-of select="substring-after(name(), ':')"/>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="name()"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
       <!-- This variable establishes the value of TAG (the parsed out tag name) under the name LABEL-->	
	<xsl:variable name="label">
		<xsl:call-template name="capitalize">
			<xsl:with-param name="label">
				<xsl:value-of select="$tag"/>
			</xsl:with-param>
		</xsl:call-template>
	</xsl:variable>
       <!--This variable parses out the _ from the olac:code element extension -->
	<xsl:variable name="code">
		<xsl:value-of select="translate(@olac:code ,'_', ' ')"/>
	</xsl:variable>
       <!-- What follows is the formatting of the display-->
           <!--This code establishes the LABEL in the left TD with certain fonts -->
				<span style="color:black ; font-weight:bold ; font-size:x-small ; font-family:'Verdana'">
					<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
					<xsl:value-of select="$label"/>
					<xsl:text>:  </xsl:text>
					<xsl:text disable-output-escaping="yes">&amp;nbsp;</xsl:text>
				</span>
             <!--This parses out the element content and extensions, and gives them parameter names (PRIMARY CODE, SECONDARY CODE, TERTIARY CODE, FOURTH CODE) to be used in the next template for display -->
				<span style="color:black; font-size:x-small ; font-family:'Verdana'">
					<xsl:choose>
						<xsl:when test="dc:creator">
							<xsl:call-template name="olac-display-format">
								<xsl:with-param name="secondaryCode">
									<xsl:value-of select="dc:creator"/>
								</xsl:with-param>
							</xsl:call-template>
						</xsl:when>
						<xsl:when test="dcterms:created">
							<xsl:call-template name="olac-display-format">
								<xsl:with-param name="secondaryCode">
									<xsl:value-of select="dcterms:created"/>
								</xsl:with-param>
							</xsl:call-template>
						</xsl:when>
						<xsl:when test="dc:source">
							<xsl:call-template name="olac-display-format">
								<xsl:with-param name="secondaryCode">
									<xsl:call-template name="capitalize">
										<xsl:with-param name="label">
											<xsl:value-of select="dc:source"/>
										</xsl:with-param>
									</xsl:call-template>
								</xsl:with-param>
							</xsl:call-template>
						</xsl:when>
						<xsl:when test="@xsi:type='olac:role'">
							<xsl:call-template name="olac-display-format">
								<xsl:with-param name="secondaryCode">
									<xsl:call-template name="capitalize">
										<xsl:with-param name="label">
											<xsl:value-of select="$code"/>
										</xsl:with-param>
									</xsl:call-template>
								</xsl:with-param>
							</xsl:call-template>
						</xsl:when>
						<xsl:otherwise>
							<xsl:call-template name="element-content"/>
						</xsl:otherwise>
					</xsl:choose>
				</span>
	</xsl:template>
    <!-- This template capitalizes the first letter of all labels-->
	<xsl:template name="capitalize">
		<xsl:param name="label"/>
		<xsl:value-of select="concat( translate(substring($label,1,1),  'abcdefghijklmnopqrstuvwxyz', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'), substring($label, 2, string-length($label)-1))"/>
	</xsl:template>
    <!-- This template establishes the displays of the content/extensions of the elements.-->
	<xsl:template name="olac-display-format">
		<xsl:param name="label"/>
		<xsl:param name="primaryCode"/>
		<xsl:param name="secondaryCode"/>
		<xsl:param name="tertiaryCode"/>
		<xsl:choose>
			<xsl:when test="$primaryCode">
				<xsl:value-of select="$primaryCode"/>
				<xsl:if test=". != ''">
					<xsl:text>:  </xsl:text>
					<xsl:call-template name="element-content"/>
				</xsl:if>
			</xsl:when>
			<xsl:when test="$secondaryCode">
				<xsl:call-template name="element-content"/>
				<xsl:text>(</xsl:text>
				<xsl:value-of select="$secondaryCode"/>
				<xsl:text>)</xsl:text>
			</xsl:when>
			<xsl:otherwise>
				<xsl:call-template name="element-content"/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
    <!-- This template formats the content of the element to allow for href-->
	<xsl:template name="element-content">
		<xsl:choose>
			<xsl:when test="starts-with(.,'http://')">
				<a href="{.}">
					<xsl:value-of select="."/>
				</a>
			</xsl:when>
			<xsl:otherwise>
				<xsl:value-of select="."/>
			</xsl:otherwise>
		</xsl:choose>
	</xsl:template>
	<xsl:template match="dc:description | dc:coverage | dcterms:spatial | dcterms:temporal | dc:format | dcterms:extent | dcterms:medium | dc:language | dc:relation | dcterms:isVersionOf | dcterms:hasVersion | dcterms:isReplacedBy | dcterms:replaces | dcterms:isRequiredBy | dcterms:requires | dcterms:isPartOf | dcterms:hasPart | dcterms:isReferencedBy | dcterms:references | dcterms:isFormatOf | dcterms:hasFormat | dcterms:conformsTo | dc:rights | dc:type | dc:title | dc:contributor | dc:subject">
		<!--By naming the elements I don't want to show in a blank template, the elements will not be brought through the above templates-->
	</xsl:template>
</xsl:stylesheet>                  
