<?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="/name:name">
    <xsl:apply-templates select="." mode="abstract" />
  </xsl:template>

  <!-- Abstract -->
  <xsl:template match="name:name" mode="abstract">
    <xsl:apply-templates select="." mode="monograph" />
  </xsl:template>

<!--
    <xsl:call-template name="logout-link" />
-->

  <!-- Monograph -->
  <xsl:template match="name:name" mode="monograph">
    <table class="monograph">
      <caption></caption>
      <thead></thead>
      <tbody>
        <xsl:apply-templates select="." mode="monograph-entry-proper-form" />
        <xsl:apply-templates select="." mode="monograph-entry-history" />
        <xsl:call-template name="table-row-empty" />
        <xsl:apply-templates select="." mode="table-row-citation" />
        <xsl:apply-templates select="." mode="table-row-sourcefile" />
      </tbody>
      <tfoot></tfoot>
    </table>
    <table class="footnotes">
      <caption></caption>
      <thead></thead>
      <tbody>
        <xsl:apply-templates select="common:annotation/common:modified" mode="footnote" />
<!--        <xsl:call-template name="support-footnote" /> -->
        <xsl:if test="name:synonyms/*/name:synonym[@type='rule40d']">
          <xsl:call-template name="footnote-rule46" />
        </xsl:if>
      </tbody>
      <tfoot></tfoot>
    </table>
    <xsl:apply-templates select="reference:bibliography" mode="bibliography" />
  </xsl:template>

  <!-- Support -->
  <xsl:template match="name:name" mode="table-row-support">
    <tr>
      <td><div>Support</div></td>
      <td><xsl:call-template name="support" /></td>
    </tr>
  </xsl:template>

  <!-- Citation -->
  <xsl:template match="name:name" mode="table-row-citation">
    <tr>
      <td><div>Citation</div></td>
      <td><xsl:apply-templates select="." mode="citation" /></td>
    </tr>
  </xsl:template>

  <!-- Name Citation -->
  <xsl:template match="name:name" mode="citation">
    <div>When referring specifically to this Abstract, please use its Digital Object Identifier.</div>
    <div class="citation"><xsl:apply-templates select="." mode="abstract-citation" /></div>
  </xsl:template>

  <!-- Source File -->
  <xsl:template match="name:name" mode="table-row-sourcefile">
    <tr>
      <td><div>Source File</div></td>
      <td><xsl:apply-templates select="." mode="sourcefile" /></td>
    </tr>
  </xsl:template>

  <!-- Source File -->
  <xsl:template match="name:name" mode="sourcefile">
    <div>
      <a>
        <xsl:attribute name="href">
          <xsl:value-of select="substring(@doi, 9)" />
          <xsl:text>.xml</xsl:text>
        </xsl:attribute>
        <xsl:value-of select="@doi" />
        <xsl:text>.xml</xsl:text>
      </a>
    </div>
  </xsl:template>

  <!-- Proper Form -->
  <xsl:template match="name:name" mode="monograph-entry-proper-form">
    <tr>
      <td><div>Proper Form</div></td>
      <td><xsl:apply-templates select="common:nomenclature/common:name-status-group" mode="proper" /></td>
    </tr>
  </xsl:template>

  <!-- Nomenclatural History -->
  <xsl:template match="name:name" mode="monograph-entry-history">
    <tr>
      <td><div>Nomenclatural History</div></td>
      <td>
        <div>
          <!-- The effective publication is not the original description for revived names. -->
          <xsl:choose>
            <xsl:when test="name:events/name:event[@type='revived']"></xsl:when>
            <xsl:otherwise>
              <xsl:apply-templates select="name:events/name:event[@type='effective-publication']" mode="original" />
            </xsl:otherwise>
          </xsl:choose>

          <!-- Taxon ranks not covered by the Code. Note: This is no longer needed after the new version of the Code July 2021. -->
<!--
          <xsl:if test="common:nomenclature/common:name-status-group/common:identifier/@rank='domain' or common:nomenclature/common:name-status-group/common:identifier/@rank='phylum'">
            <xsl:text> Taxon names above the rank of class are not covered under the rules of the International Code of Nomenclature of Prokaryotes. Therefore, this name is considered to be Not Validly Published</xsl:text>
            <xsl:if test="/name:name/reference:bibliography/reference:reference[@id='rid.1300']">
              <xsl:text> even though it appeared in the </xsl:text>
              <a class="longdesc">
                <xsl:attribute name="href">
                  <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id='rid.1300']" mode="citation-anchor" />
                </xsl:attribute>
                <xsl:text>Approved Lists of Bacterial Names</xsl:text>
              </a>
            </xsl:if>
            <xsl:text>.</xsl:text>
          </xsl:if>
-->
          <xsl:apply-templates select="name:events/name:event" mode="history">
            <xsl:sort select="date" />
          </xsl:apply-templates>

          <xsl:apply-templates select="name:events/name:event[@type='emendation']" mode="history-emendation">
            <xsl:sort select="date" />
          </xsl:apply-templates>

          <xsl:apply-templates select="name:synonyms" mode="history" />
        </div>

        <xsl:apply-templates select="." mode="history-incertae" />

        <xsl:apply-templates select="common:annotation/common:public-note" mode="history" />

      </td>
    </tr>
  </xsl:template>

  <!-- Nomenclatural History: Incertae sedis -->
  <xsl:template match="name:name" mode="history-incertae">
    <xsl:variable name="name" select="common:nomenclature/common:name-status-group/common:identifier" />
    <xsl:if test="starts-with($name, 'Incertae')">
      <br />
      <div><xsl:text>&#34;Incertae sedis&#34; (&#34;of uncertain placement&#34;) are placeholders and should not be considered to be formal names.</xsl:text></div>
    </xsl:if>
  </xsl:template>

  <!-- Nomenclatural History: Public Note -->
  <xsl:template match="common:annotation/common:public-note" mode="history">
    <br />
    <div><xsl:value-of select="text()" /></div>
  </xsl:template>

  <!-- Nomenclatural History: Judicial Opinion -->
  <xsl:template match="name:event[@type='judicial-opinion']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> This name was </xsl:text>
    <xsl:choose>
        <xsl:when test="name:opinion/@opinion-type='Conserved'">placed onto the <span title="list of conserved names of taxa"><i>nomina taxorum conservanda</i></span></xsl:when>
        <xsl:when test="name:opinion/@opinion-type='Rejected'">placed onto the <span title="list of rejected names of taxa"><i>nomina taxorum rejicienda</i></span></xsl:when>
        <xsl:when test="name:opinion/@opinion-type='OtherObservation'">affected</xsl:when>
        <xsl:otherwise>cited</xsl:otherwise>
    </xsl:choose>
    <xsl:text> by </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:text>Judicial Opinion </xsl:text>
      <xsl:value-of select="name:opinion/@opinion-number" />
    </a>
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Correction -->
  <xsl:template match="name:event[@type='correction']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <xsl:choose>
      <xsl:when test="../name:event[@reference=$refid and @type='validation']">
        <xsl:text>Upon validation, this name was corrected from </xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <a class="longdesc">
          <xsl:attribute name="href">
            <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
          </xsl:attribute>
          <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
        </a>
        <xsl:text> corrected this name from </xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:call-template name="name-name-link">
      <xsl:with-param name="status-code" select="name:correction/@from-status" />
      <xsl:with-param name="name" select="name:correction/@from-name" />
      <xsl:with-param name="rank" select="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank" />
      <xsl:with-param name="doi" select="name:correction/@from-doi" />
    </xsl:call-template>
    <xsl:text> (sic) to </xsl:text>
    <xsl:call-template name="name-name-link">
      <xsl:with-param name="status-code" select="name:correction/@to-status" />
      <xsl:with-param name="name" select="name:correction/@to-name" />
      <xsl:with-param name="rank" select="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank" />
      <xsl:with-param name="doi" select="name:correction/@to-doi" />
    </xsl:call-template>
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Revived Name -->
  <xsl:template match="name:event[@type='revived']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> The </xsl:text>
    <xsl:value-of select="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank" />
    <xsl:text> </xsl:text>
    <i><xsl:value-of select="/name:name/common:nomenclature/common:name-status-group/common:identifier" /></i>
    <xsl:text> </xsl:text>
    <xsl:text>was originally </xsl:text>
    <xsl:choose>
      <xsl:when test="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank='species' or /name:name/common:nomenclature/common:name-status-group/common:identifier/@rank='subspecies'">
        <xsl:text>described </xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>proposed </xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:text>by </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authority" />
    </a>
    <xsl:text>. It pre-dated the Approved Lists of Bacterial Names but was excluded from those lists. </xsl:text>
    <xsl:apply-templates select="../name:event[@type='effective-publication']" mode="revived" />
  </xsl:template>

  <!-- Nomenclatural History: Effective Publication for a Revived Name -->
  <xsl:template match="name:event[@type='effective-publication']" mode="revived">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> In </xsl:text>
    <xsl:value-of select="/name:name/reference:bibliography/reference:reference[@id=$refid]/reference:citation/reference:year" />
    <xsl:text> the name was revived </xsl:text>
    <!-- Checks if valid and effective reference are the same. -->
    <xsl:if test="../name:event[@type='validation']/@reference=$refid">
      <xsl:text>and validly published </xsl:text>
    </xsl:if>
    <xsl:text>by </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Effective Publication -->
  <xsl:template match="name:event[@type='effective-publication']" mode="original">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> The </xsl:text>
    <xsl:value-of select="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank" />
    <xsl:text> </xsl:text>
    <i><xsl:value-of select="/name:name/common:nomenclature/common:name-status-group/common:identifier" /></i>
    <xsl:text> </xsl:text>
    <xsl:text>was originally </xsl:text>
    <xsl:choose>
      <xsl:when test="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank='species' or /name:name/common:nomenclature/common:name-status-group/common:identifier/@rank='subspecies'">
        <xsl:text>described </xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>proposed </xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <!-- Checks if valid and effective reference are the same. -->
    <xsl:if test="../name:event[@type='validation']/@reference=$refid">
      <xsl:text>and validly published </xsl:text>
    </xsl:if>
    <xsl:text>by </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authority" />
    </a>
    <xsl:text>.</xsl:text>
  </xsl:template>

  <xsl:template match="name:event[@type='emendation']" mode="history">
  </xsl:template>

  <!-- Nomenclatural History: Emendation -->
  <xsl:template match="name:event[@type='emendation']" mode="history-emendation">
    <xsl:variable name="refid" select="@reference" />
    <xsl:choose>
      <xsl:when test="position()=1"> <!-- If this is the earliest emendation. -->
        <xsl:text> </xsl:text>
        <a class="longdesc">
          <xsl:attribute name="href">
            <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
          </xsl:attribute>
          <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
        </a>
        <xsl:text> published an emended description of this </xsl:text>
        <xsl:value-of select="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank" />
        <xsl:text> in </xsl:text>
        <xsl:value-of select="/name:name/reference:bibliography/reference:reference[@id=$refid]/reference:citation/reference:year" />
        <xsl:text>.</xsl:text>
      </xsl:when>
      <xsl:when test="position()=last() and position()=2">
        <xsl:text> A subsequent emendation was proposed by </xsl:text>
        <a class="longdesc">
          <xsl:attribute name="href">
            <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
          </xsl:attribute>
          <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
        </a>
        <xsl:text> in </xsl:text>
        <xsl:value-of select="/name:name/reference:bibliography/reference:reference[@id=$refid]/reference:citation/reference:year" />
        <xsl:text>.</xsl:text>
      </xsl:when>
      <xsl:when test="position()!=last() and position()=2">
        <xsl:text> Subsequent emendations were proposed by </xsl:text>
        <a class="longdesc">
          <xsl:attribute name="href">
            <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
          </xsl:attribute>
          <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
        </a>
        <xsl:text> in </xsl:text>
        <xsl:value-of select="/name:name/reference:bibliography/reference:reference[@id=$refid]/reference:citation/reference:year" />
      </xsl:when>
      <xsl:when test="position()!=last() and position() > 2">
        <xsl:text>, </xsl:text>
        <a class="longdesc">
          <xsl:attribute name="href">
            <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
          </xsl:attribute>
          <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
        </a>
        <xsl:text> in </xsl:text>
        <xsl:value-of select="/name:name/reference:bibliography/reference:reference[@id=$refid]/reference:citation/reference:year" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:text> and </xsl:text>
        <a class="longdesc">
          <xsl:attribute name="href">
            <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
          </xsl:attribute>
          <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
        </a>
        <xsl:text> in </xsl:text>
        <xsl:value-of select="/name:name/reference:bibliography/reference:reference[@id=$refid]/reference:citation/reference:year" />
        <xsl:text>.</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Nomenclatural History: Validation -->
  <!-- TODO: Add an if test to only show this if the name status is VP, VL, or AL. use 10.1601/nm.7917 as a test case -->
  <xsl:template match="name:event[@type='validation']" mode="history">
    <xsl:choose>
      <xsl:when test="../name:event[@type='effective-publication']/@reference=@reference"></xsl:when> <!-- If effective and valid reference are the same, then the valid publication was already in the text. -->
      <xsl:when test="@reference='rid.1300'">
        <xsl:apply-templates select="." mode="history-approved-list" />
      </xsl:when>
      <xsl:when test="@list-number">
        <xsl:apply-templates select="." mode="history-validation-list" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:variable name="refid" select="@reference" />
        <xsl:text> This name was validly published by </xsl:text>
        <xsl:apply-templates select="name:events/name:event[@type='validation']" mode="history" />
        <a class="longdesc">
          <xsl:attribute name="href">
            <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
          </xsl:attribute>
          <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authority" />
        </a>
        <xsl:text>.</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <!-- Nomenclatural History: Validation List -->
  <xsl:template match="name:event[@type='validation']" mode="history-validation-list">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> This name became validly published when it appeared on </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:text>Validation List No. </xsl:text>
      <xsl:value-of select="@list-number" />
    </a>
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Approved Lists -->
  <xsl:template match="name:event[@type='validation']" mode="history-approved-list">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> This name appeared on the </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:text>Approved Lists of Bacterial Names </xsl:text>
      <xsl:value-of select="/name:name/reference:bibliography/reference:reference[@id=$refid]/reference:citation/reference:year" />
    </a>
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms -->
  <xsl:template match="name:synonyms" mode="history">
    <xsl:apply-templates select="*/name:synonym" mode="history">
      <xsl:sort select="@date" />
    </xsl:apply-templates>
  </xsl:template>
<!--
  <xsl:template match="name:synonyms-from/name:synonym|name:synonyms-to/name:synonym" mode="history">
    <xsl:text>synonym type: </xsl:text><xsl:value-of select="@type" />
  </xsl:template>
-->
  <!-- Nomenclatural History: Synonyms From (homotypic) -->
  <xsl:template match="name:synonyms-from/name:synonym[@type='homotypic']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> established </xsl:text>
    <xsl:apply-templates select="/name:name" mode="name-link" />
    <xsl:text> as an earlier homotypic synonym of </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms To (homotypic) -->
  <xsl:template match="name:synonyms-to/name:synonym[@type='homotypic']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> established </xsl:text>
    <xsl:apply-templates select="/name:name" mode="name-link" />
    <xsl:text> as a later homotypic synonym of </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms From (heterotypic) -->
  <xsl:template match="name:synonyms-from/name:synonym[@type='heterotypic']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> established this name as an earlier heterotypic synonym of </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms To (heterotypic) -->
  <xsl:template match="name:synonyms-to/name:synonym[@type='heterotypic']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> established this name as a later heterotypic synonym of </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>
  
  <!-- Nomenclatural History: Synonyms From (replacement) -->
  <xsl:template match="name:synonyms-from/name:synonym[@type='replacement']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> replaced this </xsl:text><xsl:if test="/name:name/common:nomenclature/common:name-status-group/common:status/@illegitimate='true'">illegitimate </xsl:if><xsl:text>name with </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms To (replacement) -->
  <xsl:template match="name:synonyms-to/name:synonym[@type='replacement']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <xsl:text>This name replaces the </xsl:text><xsl:if test="/name:name/common:nomenclature/common:name-status-group/common:status/@illegitimate='true'">illegitimate </xsl:if><xsl:text>name </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms From (new combination) -->
  <xsl:template match="name:synonyms-from/name:synonym[@type='new combination']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> In </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>, </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> established </xsl:text>
    <xsl:apply-templates select="/name:name" mode="name-link" />
    <xsl:text> as the basonym of </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms To (basonym) -->
  <xsl:template match="name:synonyms-to/name:synonym[@type='basonym']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> formed this name in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text> by placing the </xsl:text>
    <xsl:apply-templates select="common:name-status-group/common:identifier/@rank" />
    <xsl:text> </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text> into the </xsl:text>
    <xsl:apply-templates select="/name:name/taxon:taxon/taxon:parent/@rank" />
    <xsl:text> </xsl:text>
    <xsl:apply-templates select="/name:name/taxon:taxon/taxon:parent/common:nomenclature/common:name-status-group" mode="name-authority-link" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms From (unification) -->
  <xsl:template match="name:synonyms-from/name:synonym[@type='unification']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> transferred the members of </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text> into this </xsl:text>
    <xsl:apply-templates select="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank" />
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms To (unification) -->
  <xsl:template match="name:synonyms-to/name:synonym[@type='unification']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> transferred the members of this </xsl:text>
    <xsl:apply-templates select="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank" />
    <xsl:text> into </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms From (conservation) -->
  <xsl:template match="name:synonyms-from/name:synonym[@type='conservation']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> conserved </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text> against this rejected </xsl:text>
    <xsl:apply-templates select="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank" />
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms To (conservation) -->
  <xsl:template match="name:synonyms-to/name:synonym[@type='conservation']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> conserved this </xsl:text>
    <xsl:apply-templates select="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank" />
    <xsl:text> against the rejected name </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms From (rank elevation) -->
  <xsl:template match="name:synonyms-from/name:synonym[@type='rank elevation']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> elevated this </xsl:text>
    <xsl:apply-templates select="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank" />
    <xsl:text> to the rank of </xsl:text>
    <xsl:apply-templates select="common:name-status-group/common:identifier/@rank" />
    <xsl:text> to form the name </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms To (rank elevation) -->
  <xsl:template match="name:synonyms-to/name:synonym[@type='rank elevation']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> elevated the </xsl:text>
    <xsl:apply-templates select="common:name-status-group/common:identifier/@rank" />
    <xsl:text> </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text> to the rank of </xsl:text>
    <xsl:apply-templates select="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank" />
    <xsl:text> to form this name </xsl:text>
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms From (rank reduction) -->
  <xsl:template match="name:synonyms-from/name:synonym[@type='rank reduction']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <xsl:text>In </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>, </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> reduced this </xsl:text>
    <xsl:apply-templates select="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank" />
    <xsl:text> to the rank of </xsl:text>
    <xsl:apply-templates select="common:name-status-group/common:identifier/@rank" />
    <xsl:text> to form </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms To (rank reduction) -->
  <xsl:template match="name:synonyms-to/name:synonym[@type='rank reduction']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <xsl:text>In </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>, </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> reduced </xsl:text>
    <xsl:apply-templates select="." mode="name-authority-link" />
    <xsl:text> to the rank of </xsl:text>
    <xsl:apply-templates select="/name:name/common:nomenclature/common:name-status-group/common:identifier/@rank" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms From (rule 40d) -->
  <xsl:template match="name:synonyms-from/name:synonym[@type='rule40d']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <xsl:apply-templates select="." mode="name-link" />
    <xsl:text> was created via Rule 40d (formerly Rule 46</xsl:text>
    <xsl:call-template name="cite-footnote"><xsl:with-param name="footnote">rule46</xsl:with-param></xsl:call-template>
    <xsl:text>) of the International Code of Nomenclature of Bacteria following the proposal of </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Nomenclatural History: Synonyms To (rule 40d) -->
  <xsl:template match="name:synonyms-to/name:synonym[@type='rule40d']" mode="history">
    <xsl:variable name="refid" select="@reference" />
    <xsl:text> </xsl:text>
    <xsl:apply-templates select="/name:name" mode="name-link" />
    <xsl:text> was created via Rule 40d (formerly Rule 46</xsl:text>
    <xsl:call-template name="cite-footnote"><xsl:with-param name="footnote">rule46</xsl:with-param></xsl:call-template>
    <xsl:text>) of the International Code of Nomenclature of Bacteria following the proposal of </xsl:text>
    <a class="longdesc">
      <xsl:attribute name="href">
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="citation-anchor" />
      </xsl:attribute>
      <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    </a>
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <xsl:template match="name:name" mode="abstract-citation">
    <xsl:apply-templates select="." mode="abstract-title" />
    <time itemprop="dateModified">
      <xsl:attribute name="datetime">
        <xsl:value-of select="common:annotation/common:snapshot/@date" /><xsl:text>T</xsl:text><xsl:value-of select="common:annotation/common:snapshot/@time" /><xsl:text>Z</xsl:text>
      </xsl:attribute>
      <xsl:value-of select="common:annotation/common:snapshot/@date-formatted" />
    </time>
    <xsl:text>. </xsl:text>
    <a>
      <xsl:attribute name="href">
        <xsl:text>https://doi.org/</xsl:text>
        <xsl:value-of select="@doi" />
      </xsl:attribute>
      <xsl:text>https://doi.org/</xsl:text>
      <xsl:value-of select="@doi" />
    </a>
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Abstract Title -->
  <xsl:template match="name:name" mode="abstract-title">
    <xsl:text>Name Abstract for </xsl:text>
    <xsl:apply-templates select="common:nomenclature/common:name-status-group" mode="proper" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <xsl:template match="name:synonym" mode="name-link">
    <xsl:call-template name="name-name-link">
      <xsl:with-param name="status-code" select="common:name-status-group/common:status/@status-code" />
      <xsl:with-param name="rank" select="common:name-status-group/common:identifier/@rank" />
      <xsl:with-param name="name" select="common:name-status-group/common:identifier" />
      <xsl:with-param name="doi" select="common:name-status-group/common:identifier/@doi" />
    </xsl:call-template>
  </xsl:template>

  <xsl:template name="footnote-rule46">
    <tr>
      <td><sup><a name="rule46">&#8224;</a></sup><xsl:text> Rule 46. &#34;The valid publication of a subspecific name which excludes the type of the species automatically creates another subspecies which includes the type and whose name bears the same specific and subspecific epithets as the name of the type.&#34; (Bacterial Code 1990)</xsl:text></td>
    </tr>
  </xsl:template>

  <xsl:template name="cite-footnote">
    <xsl:param name="footnote" />
    <sup>
      <a class="citation">
        <xsl:attribute name="href">
          <xsl:text>#</xsl:text>
          <xsl:value-of select="$footnote" />
        </xsl:attribute>
        <xsl:text>&#8224;</xsl:text>
      </a>
    </sup>
  </xsl:template>

</xsl:stylesheet>
