<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
  version="1.0"
  xmlns:name="http://namesforlife.com/ns/name"
  xmlns:taxon="http://namesforlife.com/ns/taxon"
  xmlns:exemplar="http://namesforlife.com/ns/exemplar"
  xmlns:reference="http://namesforlife.com/ns/reference"
  xmlns:common="http://namesforlife.com/ns/common"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  exclude-result-prefixes="name taxon exemplar reference common"
  >

  <xsl:include href="common.xsl" />

  <xsl:output
    method="html"
    standalone="yes"
    encoding="iso-8859-1"
    omit-xml-declaration="yes"
    cdata-section-elements="pre script style"
    indent="yes"
    media-type="text/html"
  />

  <!-- Main Entry Point -->
  <xsl:template match="/exemplar:exemplar">
    <xsl:apply-templates select="." mode="metadata" />
  </xsl:template>

  <!-- Generate Metadata -->
  <xsl:template match="exemplar:exemplar" mode="metadata">

    <title><xsl:apply-templates select="." mode="abstract-title" /></title>

    <link rel="canonical">
      <xsl:attribute name="href">
        <xsl:text>https://doi.org/</xsl:text>
        <xsl:value-of select="@doi" />
      </xsl:attribute>
    </link>

    <meta name="DESCRIPTION">
      <xsl:attribute name="content">
        <xsl:text>Physiology, characteristics and genomic data for the microbial strain </xsl:text>
        <xsl:apply-templates select="exemplar:identifiers" mode="strain-equivalencies" />
        <xsl:text>.</xsl:text>
      </xsl:attribute>
    </meta>

    <meta name="KEYWORDS">
      <xsl:attribute name="content">
        <xsl:for-each select="exemplar:identifiers/exemplar:identifier">
          <xsl:sort select="@is-laboratory-identifier" order="descending" />
          <xsl:choose>
            <xsl:when test="position()=1"></xsl:when>
            <xsl:otherwise>,</xsl:otherwise>
          </xsl:choose>
          <xsl:apply-templates select="@label" />
        </xsl:for-each>
        <xsl:text>,strain,culture,deposit,type,non-type,organism,</xsl:text>
        <xsl:for-each select="common:nomenclature/common:name-status-group">
          <xsl:choose>
            <xsl:when test="position()=1"></xsl:when>
            <xsl:otherwise>,</xsl:otherwise>
          </xsl:choose>
          <xsl:apply-templates select="common:identifier" />
        </xsl:for-each>
        <xsl:text>,Exemplar,16S,rRNA,genome</xsl:text>
      </xsl:attribute>
    </meta>

    <meta name="DCTERMS.title">
      <xsl:attribute name="content">
        <xsl:apply-templates select="." mode="abstract-title" />
      </xsl:attribute>
    </meta>

    <meta name="DCTERMS.identifier">
      <xsl:attribute name="content">
        <xsl:value-of select="@doi" />
      </xsl:attribute>
    </meta>

    <meta name="DCTERMS.format" content="text/html" />
    <meta name="DCTERMS.language" content="en" />

    <meta name="DCTERMS.publisher" content="University of California" />

    <meta name="DCTERMS.dateCopyrighted">
      <xsl:attribute name="content">
        <xsl:choose>
          <xsl:when test="common:annotation/common:created"><xsl:value-of select="common:annotation/common:created/@date" /></xsl:when>
          <xsl:otherwise>2005</xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
    </meta>

    <meta name="datePublished" id="datePublished">
      <xsl:attribute name="content">
        <xsl:choose>
          <xsl:when test="common:annotation/common:created"><xsl:value-of select="common:annotation/common:created/@date" /></xsl:when>
          <xsl:otherwise>2006-06-23</xsl:otherwise>
        </xsl:choose>
      </xsl:attribute>
    </meta>

    <xsl:if test="common:annotation/common:modified">
      <meta name="dateModified" id="dateModified">
        <xsl:attribute name="content">
          <xsl:value-of select="common:annotation/common:modified/@date" />
        </xsl:attribute>
      </meta>
    </xsl:if>

  </xsl:template>

  <!-- Abstract Title -->
  <xsl:template match="exemplar:exemplar" mode="abstract-title">
    <xsl:text>Strain </xsl:text>
    <xsl:apply-templates select="exemplar:identifiers" mode="strain-equivalencies" />
    <xsl:text> : Microbial Characteristics and Genomic Information.</xsl:text>
  </xsl:template>

</xsl:stylesheet>
