<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/1999/xhtml" xmlns:gmd="http://www.isotc211.org/2005/gmd" xmlns:gmx="http://www.isotc211.org/2005/gmx" xmlns:gco="http://www.isotc211.org/2005/gco" xmlns:srv="http://www.isotc211.org/2005/srv" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:gml="http://www.opengis.net/gml" xmlns:gml32="http://www.opengis.net/gml/3.2" exclude-result-prefixes="gmd gco srv xlink gml gml32">
	<xsl:output method="html" encoding="iso-8859-1" indent="yes" doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
	<!--
		<meta name="DC.creator" content="Peter Parslow"/>
		<meta name="DC.contributor" content="Patrick Revell"/>
		<meta name="DCTERMS.created" scheme="DCTERMS.W3CDTF" content="2011-05-16"/>
		<meta name="DCTERMS.modified" scheme="DCTERMS.W3CDTF" content="2013-05-20"/>
		<meta name="DC.description" content="This stylesheet transforms an ISO 19139 encoded metadata record into xHTML for human viewing. Specifically, it extracts the OS Terrain tile metadata elements from the XML. It is based on a 2011 stylesheet published by the UK Location Programme under OGL."/>
		<meta name="DC.publisher" content="Ordnance Survey GB"/>
		<meta name="DC.title" content="GEMINI viewing stylesheet"/>
		<meta name="eGMS.copyright" content="Crown copyright http://www.opsi.gov.uk/advice/crown-copyright/index.htm"/>
		<meta name="DC.rights" content="Open Government Licence http://www.nationalarchives.gov.uk/doc/open-government-licence/"/>
		<meta name="eGMS.status" content="1.1" />
Note 'double' GML namespace, so that this stylesheet works with whichever is in the input XML file
Doesn't - at present - look values up in the various codelists: simply outputs the @codeListValue attribute, which is 'reasonably English'
Doesn't deal with gco:nilReason
-->
	<xsl:template match="/">
		<!-- HTML head/body, with standard metadata -->
		<html>
			<head>
				<title>GEMINI record about <xsl:value-of select="gmd:MD_Metadata/gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString"/>
				</title>
				<meta name="DC.source">
					<xsl:attribute name="content">GEMINI metadata record with fileIdentifier: <xsl:value-of select="gmd:MD_Metadata/gmd:fileIdentifier/gco:CharacterString"/></xsl:attribute>
				</meta>
				<meta name="DC.publisher">
					<xsl:attribute name="content"><xsl:value-of select="gmd:MD_Metadata/gmd:contact/gmd:CI_ResponsibleParty/gmd:organisationName/gco:CharacterString"/></xsl:attribute>
				</meta>
				<meta name="DC.subject" scheme="eGMS.IPSV" content="metadata"/>
				<meta name="DC.language" scheme="DCTERMS.ISO639-2">
					<xsl:attribute name="content"><xsl:value-of select="gmd:MD_Metadata/gmd:language/gmd:LanguageCode/@codeListValue"/></xsl:attribute>
				</meta>
				<!-- insert the required CSS stylesheet in here -->
				<link rel="stylesheet" href="metadataHTMLstylesheet.css" type="text/css" media="screen"/>
			</head>
			<body>
				<xsl:apply-templates select="gmd:MD_Metadata"/>
			<script src="https://www.ordnancesurvey.co.uk/os-js/cookie-control/cookie-control.min.js"></script> 
<script src="https://www.ordnancesurvey.co.uk/os-js/cookie-control/xml.min.js"></script>
</body>
		</html>
	</xsl:template>
	<xsl:template match="gmd:MD_Metadata">
		<!-- the meat of the ISO 19139 / GEMINI transformation -->
		<!-- the idea is to use few HTML tags: h1 through h5, p, a - so that CSS can be applied -->
		<h1>OS Terrain Tile Metadata</h1>
		<hr/>
		<h2>Product Identification</h2>
		<h3 title="Collective title">Product name</h3>
		<p>
			<xsl:value-of select="gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:collectiveTitle/gco:CharacterString"/>
			(<a>
				<xsl:attribute name="href">
					<xsl:value-of select="gmd:series/gmd:DS_Series/gmd:seriesMetadata/@xlink:href" /> 
				</xsl:attribute>Series metadata</a>)
		</p>
		<h3 title="Spatial representation type code">Spatial representation</h3>
		<p>
			<xsl:value-of select="gmd:identificationInfo/*/gmd:spatialRepresentationType/gmd:MD_SpatialRepresentationTypeCode/@codeListValue"/>
		</p>
		<h3 title="INSPIRE Resource title">Tile reference</h3>
		<p title="Title">
			<xsl:value-of select="gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:title/gco:CharacterString"/>
		</p>
		<h3 title="INSPIRE Topic category">Topic category</h3>
		<xsl:for-each select="gmd:identificationInfo/*/gmd:topicCategory">
			<p title="Topic category">
				<xsl:value-of select="gmd:MD_TopicCategoryCode"/>
			</p>
		</xsl:for-each>
		<h3 title="Spatial reference system">Coordinate reference systems</h3>
		<xsl:for-each select="gmd:referenceSystemInfo">
			<p>
				<a>
					<xsl:attribute name="href">http://www.epsg-registry.org/export.htm?gml=<xsl:value-of select="gmd:MD_ReferenceSystem/gmd:referenceSystemIdentifier/gmd:RS_Identifier/gmd:code/gmx:Anchor/@xlink:href"/></xsl:attribute>
					<xsl:value-of select="gmd:MD_ReferenceSystem/gmd:referenceSystemIdentifier/gmd:RS_Identifier/gmd:code/gmx:Anchor"/>
				</a>
			</p>
		</xsl:for-each>
		<!-- section break -->
		<hr/>
		<h2 title="INSPIRE Temporal extent">Change History</h2>
		<xsl:variable name="endpos" select="gmd:identificationInfo/*/*/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:endPosition|gmd:identificationInfo/*/*/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml32:TimePeriod/gml32:endPosition"/>
		<xsl:variable name="beginpos" select="gmd:identificationInfo/*/*/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml:TimePeriod/gml:beginPosition|gmd:identificationInfo/*/*/gmd:EX_Extent/gmd:temporalElement/gmd:EX_TemporalExtent/gmd:extent/gml32:TimePeriod/gml32:beginPosition"/>
		<h3>Flying date(s)</h3>
		<xsl:if test="not($endpos=$beginpos)">
			<p title="Begin position">
				<xsl:value-of select="$beginpos"/>
			</p>
		</xsl:if>
		<p title="End position">
			<xsl:value-of select="$endpos"/>
		</p>
		<h3 title="INSPIRE Date of publication/last revision/creation">Processing date</h3>
		<p title="effective date">
			<xsl:value-of select="gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:date/gco:Date|gmd:date/gco:DateTime"/>
		</p>
		<h3>Version</h3>
		<p title="edition">
			v<xsl:value-of select="gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:edition/gco:CharacterString"/>
		</p>
		<h3 title="INSPIRE Lineage">Reason for change</h3>
		<xsl:variable name="reasonforchange" select="gmd:identificationInfo/*/gmd:citation/gmd:CI_Citation/gmd:date/gmd:CI_Date/gmd:dateType/gmd:CI_DateTypeCode/@codeListValue"/>
		<p title="date type">
			<b>
				<xsl:if test="$reasonforchange = 'creation'">new</xsl:if>
				<xsl:if test="$reasonforchange = 'revision'">modified/verified</xsl:if>
			</b> -
			<xsl:value-of select="gmd:dataQualityInfo/gmd:DQ_DataQuality/gmd:lineage/gmd:LI_Lineage/gmd:statement/gco:CharacterString"/>
		</p>
	</xsl:template>
</xsl:stylesheet>