<?xml version="1.0" encoding="UTF-8"?>
<!--
    Copyright (c) 2024, The Regents of the University of California, through
    Lawrence Berkeley National Laboratory (subject to receipt of any required
    approvals from the U.S. Dept. of Energy). All rights reserved.

    CLOCKSS system has permission to ingest, preserve, and serve this Archival Unit.
    LOCKSS system has permission to collect, preserve, and serve this Archival Unit.

    This content is licensed under a Creative Commons Attribution 3.0 International license.
    https://creativecommons.org/licenses/by/3.0/
-->
<xsl:stylesheet version="1.0" exclude-result-prefixes="name" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://namesforlife.com/ns/menu" 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">

    <xsl:output method="xml" standalone="no" encoding="UTF-8" omit-xml-declaration="no" indent="yes" />

    <xsl:param name="build" />
    <xsl:param name="snapshot" />

    <xsl:template match="/name:name">
      <xsl:comment>
    Copyright (c) 2005-2022 NamesforLife, LLC.
    All rights reserved.
</xsl:comment>
        <menu>
            <title>
                <item type="root-menutitle">
                    <xsl:choose>
                        <xsl:when test="common:nomenclature/common:name-status-group/common:status[@status-code!='AL' and @status-code!='VL' and @status-code!='VP']">&#8220;</xsl:when>
                        <xsl:otherwise>&#160;</xsl:otherwise>
                    </xsl:choose>
                    <i><xsl:value-of select="common:nomenclature/common:name-status-group/common:identifier/text()" /></i>
                    <xsl:choose>
                        <xsl:when test="common:nomenclature/common:name-status-group/common:status[@status-code!='AL' and @status-code!='VL' and @status-code!='VP']">&#8221;</xsl:when>
                        <xsl:otherwise>&#160;</xsl:otherwise>
                    </xsl:choose>
                </item>
            </title>
            <spacer />
            <xsl:apply-templates select="." mode="submenu-nomenclature" />
            <xsl:apply-templates select="name:synonyms" mode="submenu-synonyms" />
            <xsl:apply-templates select="taxon:taxon" mode="submenu-taxonomy" />
            <xsl:apply-templates select="taxon:taxon/exemplar:exemplars" mode="submenu-exemplars" />
            <xsl:apply-templates select="reference:bibliography" mode="submenu-bibliography" />
            <separator />
            <spacer />
            <xsl:apply-templates select="." mode="submenu-help" />
        </menu>
    </xsl:template>

    <xsl:template match="name:name" mode="submenu-nomenclature">
        <submenu>
            <title>
                <item>Nomenclature</item>
            </title>
            <subtitle>
                <xsl:apply-templates select="." mode="abstract-link" />
            </subtitle>
            <spacer />
            <xsl:apply-templates select="." mode="submenu-authority" />
            <xsl:apply-templates select="." mode="submenu-status" />
            <xsl:apply-templates select="." mode="submenu-history" />
            <xsl:apply-templates select="taxon:taxon" mode="submenu-nomenclatural-type" />
            <xsl:apply-templates select="name:events" mode="submenu-events" />
            <xsl:apply-templates select="." mode="submenu-preferred-name" />
        </submenu>
    </xsl:template>

    <xsl:template match="name:synonym" mode="submenu-synonym">
        <xsl:variable name="refid"><xsl:value-of select="@reference" /></xsl:variable>
        <submenu>
            <title>
                <item>
                    <xsl:attribute name="type"><xsl:value-of select="translate(@type,' ','-')" /></xsl:attribute>
                    <xsl:choose>
                        <xsl:when test="@type='replacement' and name(..)='synonyms-to'">Replaces </xsl:when>
                        <xsl:when test="@type='replacement' and name(..)='synonyms-from'">Replaced by </xsl:when>
                        <xsl:when test="@type='unification'">Unification with </xsl:when>
                        <xsl:when test="@type='heterotypic' and name(..)='synonyms-from'">pro synon. </xsl:when>
                        <xsl:when test="@type='homotypic' and name(..)='synonyms-from'">pro synon. </xsl:when>
                        <xsl:when test="@type='basonym'">comb. nov. </xsl:when>
                        <xsl:when test="@type='rule40d'"></xsl:when>
                        <xsl:otherwise></xsl:otherwise>
                    </xsl:choose>
                    <i><xsl:value-of select="common:name-status-group/common:identifier" /></i>
                    <xsl:choose>
                        <xsl:when test="@type='replacement'"></xsl:when>
                        <xsl:when test="@type='unification'"></xsl:when>
                        <xsl:when test="@type='heterotypic' and name(..)='synonyms-to'"> pro synon.</xsl:when>
                        <xsl:when test="@type='homotypic' and name(..)='synonyms-to'"> pro synon.</xsl:when>
                        <xsl:when test="@type='new combination'"> comb. nov.</xsl:when>
                        <xsl:when test="@type='rule40d'"></xsl:when>
                        <xsl:otherwise></xsl:otherwise>
                    </xsl:choose>
                </item>
            </title>
            <subtitle>
                <item>
                    <xsl:value-of select="@type" />
                    <xsl:text> (</xsl:text>
                    <xsl:value-of select="@date" />
                    <xsl:text>)</xsl:text>
                </item>
            </subtitle>
            <spacer />
            <xsl:apply-templates select="." mode="menu-name" />
            <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="submenu-reference">
                <xsl:with-param name="title">Citation</xsl:with-param>
            </xsl:apply-templates>
        </submenu>
    </xsl:template>

    <xsl:template match="name:name" mode="submenu-preferred-name">
        <submenu>
            <title>
                <item>Preferred Name</item>
            </title>
            <subtitle>
                <item>Preferred Name</item>
            </subtitle>
            <spacer />
            <xsl:if test="not(@doi=common:nomenclature/common:name-status-group/common:status/@current-name-doi)">
                <item type="menu">
                    <xsl:attribute name="id"><xsl:text>https://doi.org/</xsl:text><xsl:value-of select="common:nomenclature/common:name-status-group/common:status/@current-name-doi" /></xsl:attribute>
<!--
                    <xsl:choose>
                        <xsl:when test="common:nomenclature/common:name-status-group/common:status[@status-code!='AL' and @status-code!='VL' and @status-code!='VP']">&#8220;</xsl:when>
                        <xsl:otherwise>&#160;</xsl:otherwise>
                    </xsl:choose>
-->
                    <i><xsl:value-of select="common:nomenclature/common:name-status-group/common:status/@current-name" /></i>
<!--
                    <xsl:choose>
                        <xsl:when test="common:nomenclature/common:name-status-group/common:status[@status-code!='AL' and @status-code!='VL' and @status-code!='VP']">&#8221;</xsl:when>
                        <xsl:otherwise>&#160;</xsl:otherwise>
                    </xsl:choose>
-->
                </item>
            </xsl:if>
        </submenu>
    </xsl:template>

    <xsl:template match="name:name" mode="submenu-authority">
        <submenu type="info">
            <title>
                <item type="info">Authority</item>
            </title>
            <content type="clipboard">
                <xsl:choose>
                    <xsl:when test="common:nomenclature/common:name-status-group/common:status[@status-code!='AL' and @status-code!='VL' and @status-code!='VP']">&#8220;</xsl:when>
                    <xsl:otherwise></xsl:otherwise>
                </xsl:choose>
                <i><xsl:value-of select="common:nomenclature/common:name-status-group/common:identifier/text()" /></i>
                <xsl:choose>
                    <xsl:when test="common:nomenclature/common:name-status-group/common:status[@status-code!='AL' and @status-code!='VL' and @status-code!='VP']">&#8221;</xsl:when>
                    <xsl:otherwise></xsl:otherwise>
                </xsl:choose>
            <xsl:text> </xsl:text><xsl:value-of select="common:nomenclature/common:name-status-group/common:authority" /></content>
        </submenu>
    </xsl:template>

    <xsl:template match="name:name" mode="submenu-status">
        <submenu type="info">
            <title>
                <item type="info"><xsl:value-of select="translate(substring(common:nomenclature/common:name-status-group/common:identifier/@rank,1,1),'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')" /><xsl:value-of select="substring(common:nomenclature/common:name-status-group/common:identifier/@rank, 2)" /><xsl:text> Status</xsl:text></item>
            </title>
            <content>
                <list>
                    <xsl:if test="common:nomenclature/common:name-status-group/common:status/@status-code='X'">
                        <list-item>This name is currently queued for curation.</list-item>
                    </xsl:if>
                    <xsl:if test="common:nomenclature/common:name-status-group/common:status/@status-code='NVP'">
                        <list-item>This name is <b>Not Validly Published</b> (NVP).</list-item>
                    </xsl:if>
                    <xsl:if test="common:nomenclature/common:name-status-group/common:status/@status-code='AL'">
                        <list-item>This name is <b>Validly Published</b> via the Approved Lists.</list-item>
                    </xsl:if>
                    <xsl:if test="common:nomenclature/common:name-status-group/common:status/@status-code='VL'">
                        <list-item>This name is <b>Validly Published</b> via the Validation Lists.</list-item>
                    </xsl:if>
                    <xsl:if test="common:nomenclature/common:name-status-group/common:status/@status-code='VP'">
                        <list-item>This name is <b>Validly Published</b>.</list-item>
                    </xsl:if>
                    <xsl:if test="common:nomenclature/common:name-status-group/common:status/@conserved='true'">
                        <list-item>This name is <b>conserved</b> via Judicial Opinion.</list-item>
                    </xsl:if>
                    <xsl:if test="common:nomenclature/common:name-status-group/common:status/@rejected='true'">
                        <list-item>This name was <b>rejected</b> via Judicial Opinion.</list-item>
                    </xsl:if>
                    <xsl:if test="common:nomenclature/common:name-status-group/common:status/@illegitimate='true'">
                        <list-item>This name is <b>illegitimate</b>.</list-item>
                    </xsl:if>
                    <xsl:if test="common:nomenclature/common:name-status-group/common:status/@candidatus='true'">
                        <list-item>This name is <b>Candidatus</b> (Not Validly Published) and therefore lacks a type deposit.</list-item>
                    </xsl:if>
                    <xsl:for-each select="name:events/name:event[@type='correction']">
                        <list-item><xsl:apply-templates select="." mode="text" /></list-item>
                    </xsl:for-each>
                    <xsl:choose>
                        <xsl:when test="common:nomenclature/common:name-status-group/common:status/@is-current='true'">
                            <list-item>This is the preferred name for this taxon.</list-item>
                        </xsl:when>
                        <xsl:otherwise>
                            <list-item>This is <b>not</b> the preferred name for this taxon.</list-item>
                            <list-item>
                                <xsl:text>The </xsl:text><b>preferred name</b><xsl:text> is </xsl:text>
                                <i><xsl:value-of select="common:nomenclature/common:name-status-group/common:status/@current-name" /></i>
                                <xsl:text>.</xsl:text>
                            </list-item>
                        </xsl:otherwise>
                    </xsl:choose>
                    <xsl:if test="/name:name/common:nomenclature/common:name-status-group/common:identifier[@rank='subspecies']">
                        <xsl:if test="/name:name/name:synonyms/name:synonyms-to/name:synonym[@type='rule40d']">
                            <list-item>This name has coordinate status to <i><xsl:value-of select="/name:name/name:synonyms/name:synonyms-to/name:synonym[@type='rule40d']/common:name-status-group/common:identifier" /></i> via Rule 40d.</list-item>
                        </xsl:if>
                    </xsl:if>
                    <xsl:if test="common:annotation/common:public-note">
                        <list-item><xsl:value-of select="common:annotation/common:public-note" /></list-item>
                    </xsl:if>
                    <xsl:choose>
                        <xsl:when test="common:annotation/common:modified">
                            <list-item type="footer">This record was last revised on <xsl:value-of select="common:annotation/common:modified/@date-formatted" />.</list-item>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:if test="common:annotation/common:created">
                                <list-item type="footer">This record was last revised on <xsl:value-of select="common:annotation/common:created/@date-formatted" />.</list-item>
                          </xsl:if>
                        </xsl:otherwise>
                    </xsl:choose>
                </list>
            </content>
            <external-link>
                <xsl:attribute name="url">
                    <xsl:text>https://doi.org/</xsl:text><xsl:value-of select="common:nomenclature/common:name-status-group/common:identifier/@doi" />
                </xsl:attribute>
                <xsl:text>NamesforLife Taxonomic Abstract</xsl:text>
            </external-link>
            <xsl:if test="name(.)!='name'">
                <namesforlife-link>
                    <xsl:attribute name="label">
                        <xsl:text>Open Menu: </xsl:text>
                    </xsl:attribute>
                    <xsl:attribute name="url">
                        <xsl:text>https://doi.org/</xsl:text><xsl:value-of select="common:nomenclature/common:name-status-group/common:identifier/@doi" />
                    </xsl:attribute>
                    <i><xsl:value-of select="common:nomenclature/common:name-status-group/common:identifier" /></i>
                </namesforlife-link>
            </xsl:if>
        </submenu>
    </xsl:template>

    <xsl:template match="name:event[@type='correction']" mode="text">
        <xsl:text>This name was </xsl:text><b>corrected</b><xsl:text> from </xsl:text><i><xsl:value-of select="name:correction/@from-name" /></i><xsl:text> to </xsl:text><i><xsl:value-of select="name:correction/@to-name" /></i><xsl:text>.</xsl:text>
        <newline />
    </xsl:template>

    <xsl:template match="taxon:taxon" mode="submenu-nomenclatural-type">
        <submenu>
            <title>
                <item>Nomenclatural Type</item>
            </title>
            <subtitle>
                <item>
                    <xsl:choose>
                        <xsl:when test="@rank='class' or @rank='subclass'">Type Order</xsl:when>
                        <xsl:when test="@rank='order' or @rank='suborder' or @rank='family' or @rank='subfamily'">Type Genus</xsl:when>
                        <xsl:when test="@rank='genus' or @rank='subgenus'">Type Species</xsl:when>
                        <xsl:when test="@rank='species' or @rank='subspecies'">Type Strain</xsl:when>
                        <xsl:otherwise>Nomenclatural Type</xsl:otherwise>
                    </xsl:choose>
                </item>
            </subtitle>
            <spacer />
            <xsl:choose>
              <xsl:when test="@rank='species' or @rank='subspecies'"><xsl:apply-templates select="exemplar:exemplars" mode="type-exemplar-item" /></xsl:when>
              <xsl:otherwise><xsl:apply-templates select="common:nomenclatural-type" mode="menu-name" /></xsl:otherwise>
            </xsl:choose>
        </submenu>
    </xsl:template>

    <xsl:template match="name:name" mode="submenu-history">
        <submenu type="info">
            <title>
                <item type="info">Nomenclatural History</item>
            </title>
            <content type="clipboard"><xsl:apply-templates select="." mode="monograph-entry-history" /></content>
        </submenu>
    </xsl:template>

    <xsl:template match="name:events" mode="submenu-events">
        <submenu>
            <title>
                <item>Nomenclatural Events</item>
            </title>
            <subtitle>
                <item>Nomenclatural Events</item>
            </subtitle>
            <spacer />
            <xsl:apply-templates select="name:event" mode="submenu-events">
                <xsl:sort select="@date" order="ascending" />
                <xsl:sort select="@type" order="ascending" />
            </xsl:apply-templates>
        </submenu>
    </xsl:template>

    <xsl:template match="name:event[@type='validation']" mode="submenu-events">
        <xsl:variable name="refid"><xsl:value-of select="@reference" /></xsl:variable>
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="submenu-reference">
            <xsl:with-param name="title">
              <xsl:value-of select="@date" />
              <xsl:text> Validation</xsl:text>
            </xsl:with-param>
        </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="name:event[@type='effective-publication']" mode="submenu-events">
        <xsl:variable name="refid"><xsl:value-of select="@reference" /></xsl:variable>
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="submenu-reference">
            <xsl:with-param name="title">
              <xsl:value-of select="@date" />
              <xsl:text> Effective Publication</xsl:text>
              <xsl:if test="../name:event[@type='revived']"> (Revived)</xsl:if>
            </xsl:with-param>
        </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="name:event[@type='emendation']" mode="submenu-events">
        <xsl:variable name="refid"><xsl:value-of select="@reference" /></xsl:variable>
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="submenu-reference">
            <xsl:with-param name="title">
              <xsl:value-of select="@date" />
              <xsl:text> Emendation</xsl:text>
            </xsl:with-param>
        </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="name:event[@type='correction']" mode="submenu-events">
        <xsl:variable name="refid"><xsl:value-of select="@reference" /></xsl:variable>
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="submenu-reference">
            <xsl:with-param name="title">
              <xsl:value-of select="@date" />
              <xsl:text> Correction</xsl:text>
            </xsl:with-param>
        </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="name:event[@type='revived']" mode="submenu-events">
        <xsl:variable name="refid"><xsl:value-of select="@reference" /></xsl:variable>
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="submenu-reference">
            <xsl:with-param name="title">
              <xsl:value-of select="@date" />
              <xsl:text> Original Publication (Invalid)</xsl:text>
            </xsl:with-param>
        </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="name:event[@type='judicial-opinion']" mode="submenu-events">
        <xsl:variable name="refid"><xsl:value-of select="@reference" /></xsl:variable>
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="submenu-reference">
            <xsl:with-param name="title">
              <xsl:value-of select="@date" />
              <xsl:text> Judicial Opinion </xsl:text>
              <xsl:value-of select="name:opinion/@opinion-number" />
            </xsl:with-param>
        </xsl:apply-templates>
    </xsl:template>

    <xsl:template match="name:synonyms" mode="submenu-synonyms">
        <submenu>
            <title>
                <item>Synonyms</item>
            </title>
            <xsl:if test="count(name:synonyms-to/name:synonym) &gt; 0">
                <subtitle>
                    <item>Earlier Synonyms</item>
                </subtitle>
                <spacer />
                <xsl:apply-templates select="name:synonyms-to/name:synonym" mode="submenu-synonym">
                    <xsl:sort select="@date" order="ascending" />
                </xsl:apply-templates>
            </xsl:if>
            <xsl:if test="count(name:synonyms-from/name:synonym) &gt; 0">
                <subtitle>
                    <item>Later Synonyms</item>
                </subtitle>
                <spacer />
                <xsl:apply-templates select="name:synonyms-from/name:synonym" mode="submenu-synonym">
                    <xsl:sort select="@date" order="ascending" />
                </xsl:apply-templates>
            </xsl:if>
        </submenu>
    </xsl:template>

    <xsl:template match="taxon:taxon" mode="submenu-taxonomy">
        <submenu>
            <title>
                <item>Taxonomy</item>
            </title>
            <subtitle>
                <xsl:apply-templates select="." mode="abstract-link" />
            </subtitle>
            <spacer />
            <xsl:apply-templates select="." mode="submenu-taxonomy-parent" />
            <xsl:apply-templates select="." mode="submenu-taxonomy-siblings" />
            <xsl:apply-templates select="." mode="submenu-taxonomy-children" />
            <separator />
            <xsl:apply-templates select="taxon:taxonomic-equivalence" mode="submenu-taxonomic-equivalence" />
        </submenu>
    </xsl:template>

    <xsl:template match="taxon:taxonomic-equivalence" mode="submenu-taxonomic-equivalence">
        <submenu>
            <title>
                <item>Related Taxonomic Records</item>
            </title>
            <subtitle>
                <item>Related Taxa</item>
            </subtitle>
            <spacer />
            <xsl:apply-templates select="taxon:related-taxon" mode="menu-item" />
        </submenu>
    </xsl:template>

    <xsl:template match="taxon:related-taxon[@nomos='NCBI Taxonomy']" mode="menu-item">
        <item type="link">
            <external-link>
                <xsl:attribute name="url">
                    <xsl:text>https://www.ncbi.nlm.nih.gov/Taxonomy/Browser/wwwtax.cgi?id=</xsl:text>
                    <xsl:value-of select="@accession" />
                </xsl:attribute>
                <xsl:text>NCBI TaxId </xsl:text><xsl:value-of select="@accession" />
            </external-link>
        </item>
    </xsl:template>

    <xsl:template match="taxon:taxon" mode="submenu-taxonomy-parent">
        <submenu>
            <title>
                <item>Parent Taxon</item>
            </title>
            <subtitle>
                <item>Parent Taxon</item>
            </subtitle>
            <spacer />
            <xsl:apply-templates select="taxon:parent" mode="menu-name" />
        </submenu>
    </xsl:template>

    <xsl:template match="taxon:taxon" mode="submenu-taxonomy-siblings">
        <submenu>
            <title>
                <item>Taxonomic Siblings</item>
            </title>
            <subtitle>
                <item>Taxonomic Siblings</item>
            </subtitle>
            <spacer />
            <xsl:apply-templates select="taxon:sibling" mode="menu-name">
              <xsl:sort select="contains(common:nomenclature/common:name-status-group/common:identifier, 'sp.')" order="ascending" />
              <xsl:sort select="@doi=../common:nomenclatural-type/common:name-status-group/common:identifier/@taxon-doi" order="descending" />
              <xsl:sort select="common:nomenclature/common:name-status-group/common:identifier" order="ascending" />
            </xsl:apply-templates>
        </submenu>
    </xsl:template>

    <xsl:template match="taxon:taxon" mode="submenu-taxonomy-children">
        <submenu>
            <title>
                <item>Child Taxa</item>
            </title>
            <subtitle>
                <item>Child Taxa</item>
            </subtitle>
            <spacer />
            <xsl:apply-templates select="taxon:child" mode="menu-name">
              <xsl:sort select="contains(common:nomenclature/common:name-status-group/common:identifier, 'sp.')" order="ascending" />
              <xsl:sort select="@doi=../common:nomenclatural-type/common:name-status-group/common:identifier/@taxon-doi" order="descending" />
              <xsl:sort select="common:nomenclature/common:name-status-group/common:identifier" order="ascending" />
            </xsl:apply-templates>
        </submenu>
    </xsl:template>

    <xsl:template match="common:nomenclatural-type" mode="menu-name">
        <xsl:choose>
            <xsl:when test="common:name-status-group">
                <item type="menu">
                    <xsl:attribute name="id"><xsl:text>https://doi.org/</xsl:text><xsl:value-of select="common:name-status-group/common:identifier/@doi" /></xsl:attribute>
                    <xsl:choose>
                        <xsl:when test="common:name-status-group/common:status[@status-code!='AL' and @status-code!='VL' and @status-code!='VP']">&#8220;</xsl:when>
                        <xsl:otherwise>&#160;</xsl:otherwise>
                    </xsl:choose>
                    <i><xsl:value-of select="common:name-status-group/common:identifier/text()" /></i>
                    <xsl:choose>
                        <xsl:when test="common:name-status-group/common:status[@status-code!='AL' and @status-code!='VL' and @status-code!='VP']">&#8221;</xsl:when>
                        <xsl:otherwise>&#160;</xsl:otherwise>
                    </xsl:choose>
                </item>
            </xsl:when>
            <xsl:otherwise>
                <submenu>
                    <title>
                        <item>No nomenclatural type available.</item>
                    </title>
                </submenu>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="taxon:parent|taxon:sibling|taxon:child" mode="menu-name">
        <item type="menu">
            <xsl:attribute name="id"><xsl:text>https://doi.org/</xsl:text><xsl:value-of select="common:nomenclature/common:name-status-group/common:identifier/@doi" /></xsl:attribute>
            <xsl:choose>
                <xsl:when test="common:nomenclature/common:name-status-group/common:status[@status-code!='AL' and @status-code!='VL' and @status-code!='VP']">&#8220;</xsl:when>
                <xsl:otherwise>&#160;</xsl:otherwise>
            </xsl:choose>
            <i><xsl:value-of select="common:nomenclature/common:name-status-group/common:identifier/text()" /></i>
            <xsl:if test="@doi=../common:nomenclatural-type/common:name-status-group/common:identifier/@taxon-doi"><sup>T</sup></xsl:if>
            <xsl:choose>
                <xsl:when test="common:nomenclature/common:name-status-group/common:status[@status-code!='AL' and @status-code!='VL' and @status-code!='VP']">&#8221;</xsl:when>
                <xsl:otherwise>&#160;</xsl:otherwise>
            </xsl:choose>
        </item>
    </xsl:template>

    <xsl:template match="name:synonym" mode="menu-name">
        <item type="menu">
            <xsl:attribute name="id"><xsl:text>https://doi.org/</xsl:text><xsl:value-of select="common:name-status-group/common:identifier/@doi" /></xsl:attribute>
            <xsl:choose>
                <xsl:when test="common:name-status-group/common:status[@status-code!='AL' and @status-code!='VL' and @status-code!='VP']">&#8220;</xsl:when>
                <xsl:otherwise>&#160;</xsl:otherwise>
            </xsl:choose>
            <i><xsl:value-of select="common:name-status-group/common:identifier/text()" /></i>
            <xsl:choose>
                <xsl:when test="common:name-status-group/common:status[@status-code!='AL' and @status-code!='VL' and @status-code!='VP']">&#8221;</xsl:when>
                <xsl:otherwise>&#160;</xsl:otherwise>
            </xsl:choose>
        </item>
    </xsl:template>

    <!-- This mode is specifically for the nomenclatural type (type exemplar) submenu for species and subspecies. -->
    <xsl:template match="exemplar:exemplars" mode="type-exemplar-item">
        <xsl:variable name="type-exemplar-doi" select="../common:nomenclatural-type/@nomenclatural-type-exemplar" />
        <xsl:choose>
            <xsl:when test="../common:nomenclatural-type/@nomenclatural-type-exemplar">
                <xsl:apply-templates select="exemplar:exemplar[@doi=$type-exemplar-doi]" mode="submenu-exemplar" />
            </xsl:when>
            <xsl:otherwise>
                <submenu>
                    <title>
                        <item>No type strain available.</item>
                    </title>
                </submenu>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="exemplar:exemplars" mode="submenu-exemplars">
        <xsl:variable name="type-exemplar-doi" select="../common:nomenclatural-type/@nomenclatural-type-exemplar" />
        <submenu>
            <title>
                <item>Strain Information</item>
            </title>
            <!-- Only populate the submenus if exemplars are present. -->
            <xsl:if test="exemplar:exemplar">
                <subtitle>
                    <item>Type Strain</item>
                </subtitle>
                <spacer />
                <xsl:apply-templates select="." mode="type-exemplar-item" />
                <xsl:if test="count(exemplar:exemplar[not(@doi=$type-exemplar-doi)]) &gt; 0">
                    <subtitle>
                        <item>Non-Type Strains</item>
                    </subtitle>
                    <spacer />
                    <!-- Suppresses empty exemplars (no identifiers nor features) for non-type exemplars. -->
                    <xsl:for-each select="exemplar:exemplar[not(@doi=$type-exemplar-doi) and ((count(exemplar:identifiers/exemplar:identifier) + count(exemplar:features/exemplar:feature) &gt; 0))]">
                        <!-- When sorting, the number of features is more important than the number of strains. -->
                        <xsl:sort select="count(exemplar:identifiers/exemplar:identifier) + (2 * count(exemplar:features/exemplar:feature))" data-type="number" order="descending" />
                        <xsl:if test="not(position() &gt; 15)">
                            <xsl:apply-templates select="." mode="submenu-exemplar" />
                        </xsl:if>
                    </xsl:for-each>
                    <xsl:variable name="available-exemplars" select="count(exemplar:exemplar[not(@doi=$type-exemplar-doi) and ((count(exemplar:identifiers/exemplar:identifier) + count(exemplar:features/exemplar:feature) &gt; 0))])" />
                    <xsl:if test="$available-exemplars &gt; 15">
                        <separator />
                        <xsl:apply-templates select=".." mode="abstract-link">
                            <xsl:with-param name="label"><xsl:text>+ </xsl:text><xsl:value-of select="$available-exemplars - 15" /><xsl:text> additional strains</xsl:text></xsl:with-param>
                        </xsl:apply-templates>
                    </xsl:if>
                </xsl:if>
            </xsl:if>
        </submenu>
    </xsl:template>

    <xsl:template match="exemplar:exemplar" mode="submenu-exemplar">
        <submenu>
            <xsl:apply-templates select="." mode="menu-title" />
            <subtitle>
                <xsl:apply-templates select="." mode="abstract-link" />
            </subtitle>
            <spacer />
            <xsl:apply-templates select="exemplar:identifiers" mode="submenu" />
            <xsl:apply-templates select="exemplar:features" mode="submenu" />
            <xsl:apply-templates select="exemplar:variant" mode="menu-item" />
            <xsl:apply-templates select="exemplar:biosafety-level" mode="menu-item" />
        </submenu>
    </xsl:template>

    <xsl:template match="exemplar:exemplar" mode="menu-title">
        <xsl:variable name="equivalencies"><xsl:apply-templates select="exemplar:identifiers" mode="strain-equivalencies" /></xsl:variable>
        <title>
            <item><xsl:value-of disable-output-escaping="yes" select="substring($equivalencies, 1, 20)" /><xsl:if test="string-length($equivalencies) &gt; 20"><xsl:text>...</xsl:text></xsl:if></item>
        </title>
    </xsl:template>

    <xsl:template match="exemplar:biosafety-level" mode="menu-item">
        <submenu type="info">
            <title>
                <item type="info">
                    <xsl:text>Risk Group</xsl:text>
                </item>
            </title>
            <content>
                <list>
                    <list-item>
                        <xsl:attribute name="type">
                            <xsl:choose>
                                <xsl:when test="@code='BSL-1'">information</xsl:when>
                                <xsl:when test="@code='BSL-2'">caution</xsl:when>
                                <xsl:otherwise>warning</xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                        <xsl:value-of select="@description" />
                    </list-item>
                    <xsl:choose>
                        <xsl:when test="@code='BSL-1'"><list-item>This strain is not known to cause disease in healthy adult humans.</list-item></xsl:when>
                        <xsl:when test="@code='BSL-2'"><list-item>This strain presents a moderate risk and should be handled under BSL-2 guidelines.</list-item></xsl:when>
                        <xsl:when test="@code='BSL-3'"><list-item>This strain can cause serious and potentially lethal disease in humans.</list-item><list-item>Handling of this strain requires the use of BSL-3 laboratory practices and containment.</list-item></xsl:when>
                        <xsl:when test="@code='BSL-3AG'"><list-item>This strain is known to cause severe to fatal disease in livestock.</list-item><list-item>Handling of this strain requires the use of BSL-3-Ag laboratory practices and containment.</list-item></xsl:when>
                        <xsl:when test="@code='BSL-4'"><list-item>This strain is known to cause severe to fatal disease in humans for which there are no available vaccines or treatments.</list-item><list-item>Handling of this strain requires the use of BSL-4 laboratory practices and containment.</list-item></xsl:when>
                    </xsl:choose>
                    <xsl:choose>
                        <xsl:when test="@code!='BSL-1'"><list-item>All infectious materials should be handled under the supervision of a competent and knowledgeable scientist.</list-item></xsl:when>
                    </xsl:choose>
                    <list-item>It is ultimately the recipient&#39;s and their institution&#39;s responsibility to determine the biosafety level and work with the material under the appropriate containment for the laboratory manipulations being performed.</list-item>
                    <list-item>Information on agent risk assessment may be found in the Agent Summary Statements of <external-link url="https://www.cdc.gov/biosafety/publications/bmbl5/"><xsl:text>HHS Publication No. (CDC) 93-8395</xsl:text></external-link>.</list-item>
                </list>
            </content>
        </submenu>
    </xsl:template>

    <xsl:template match="exemplar:select-agent" mode="menu-item">
        <submenu type="info">
            <title>
                <item type="info">Select Agent</item>
            </title>
            <content>
                <list>
                    <list-item>
                      <xsl:choose>
                        <xsl:when test="@code='BSL-1'">1</xsl:when>
                        <xsl:when test="@code='BSL-2'">2</xsl:when>
                        <xsl:when test="@code='BSL-3'">3</xsl:when>
                        <xsl:when test="@code='BSL-3AG'">3ag</xsl:when>
                        <xsl:when test="@code='BSL-4'">4</xsl:when>
                      </xsl:choose>
                    </list-item>
                    <list-item type="footer"><xsl:value-of select="@description" /></list-item>
                </list>
            </content>
        </submenu>
    </xsl:template>

    <xsl:template match="exemplar:variant" mode="menu-item">
        <item type="link">
            <external-link>
                <xsl:attribute name="url">
                    <xsl:text>https://doi.org/10.1601/</xsl:text>
                    <xsl:value-of select="@code" />
                </xsl:attribute>
                <xsl:value-of select="@description" />
                <xsl:text> </xsl:text>
                <xsl:apply-templates />
            </external-link>
        </item>
    </xsl:template>

    <!-- Generates the strain equivalencies string for a set of deposits. -->
    <xsl:template match="exemplar:identifiers" mode="strain-equivalencies">
      <xsl:choose>
        <xsl:when test="count(exemplar:identifier)=0"><xsl:value-of select="@doi" /></xsl:when>
        <xsl:otherwise>
          <xsl:for-each select="exemplar:identifier">
            <xsl:sort select="@is-laboratory-identifier" order="descending" />
            <xsl:if test="position()!=1"><xsl:text> </xsl:text></xsl:if>
            <xsl:if test="position()=2"><xsl:text>(</xsl:text></xsl:if>
            <xsl:if test="position()!=1"><xsl:text>=</xsl:text></xsl:if>
            <xsl:value-of select="@label" />
            <xsl:if test="position()!=1 and position()=last()"><xsl:text>)</xsl:text></xsl:if>
          </xsl:for-each>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:template>

    <xsl:template match="exemplar:identifiers" mode="submenu">
        <submenu>
            <title>
                <item>Culture Deposits</item>
            </title>
            <subtitle>
                <item>Strain Identifiers</item>
            </subtitle>
            <spacer />
            <xsl:apply-templates select="exemplar:identifier" mode="menu-item">
                <xsl:sort select="@is-laboratory-identifier" order="descending" />
            </xsl:apply-templates>
        </submenu>
    </xsl:template>

    <xsl:template match="exemplar:features" mode="submenu">
        <submenu>
            <title>
                <item>Curated Features</item>
            </title>
            <subtitle>
                <item>Features</item>
            </subtitle>
            <spacer />
            <xsl:apply-templates select="." mode="menu-item" />
        </submenu>
    </xsl:template>
    
    <xsl:template match="exemplar:identifier" mode="menu-item">
        <item type="label">
          <xsl:value-of select="@label" />
        </item>
    </xsl:template>

    <xsl:template match="exemplar:features" mode="menu-item">
        <xsl:if test="count(exemplar:feature[@code='10.1601.fr.16S'])">
            <!-- <item type="label"><xsl:value-of select="@description" /></item> -->
            <xsl:apply-templates select="exemplar:feature[@code='10.1601.fr.16S']" mode="submenu-feature-information" />
        </xsl:if>
        <xsl:if test="count(exemplar:feature[@code='10.1601.fr.assembly'])">
            <!-- <item type="label"><xsl:value-of select="@description" /></item> -->
            <xsl:apply-templates select="exemplar:feature[@code='10.1601.fr.assembly']" mode="submenu-feature-information" />
        </xsl:if>
        <xsl:if test="count(exemplar:feature[@code='10.1601.fr.project'])">
            <!-- <item type="label"><xsl:value-of select="@description" /></item> -->
            <xsl:apply-templates select="exemplar:feature[@code='10.1601.fr.project']" mode="submenu-feature-information" />
        </xsl:if>
        <xsl:if test="count(exemplar:feature[@code='10.1601.fr.chromosome' or @code='10.1601.fr.plasmid' or @code='10.1601.fr.phage'])">
            <!-- <item type="label">Genomic Sequence Data</item> -->
            <xsl:apply-templates select="exemplar:feature[@code='10.1601.fr.chromosome' or @code='10.1601.fr.plasmid' or @code='10.1601.fr.phage']" mode="submenu-feature-information" />
        </xsl:if>
        <xsl:if test="count(exemplar:feature[@code='10.1601.fr.gold'])">
            <!-- <item type="label"><xsl:value-of select="@description" /></item> -->
            <xsl:apply-templates select="exemplar:feature[@code='10.1601.fr.gold']" mode="submenu-feature-information" />
        </xsl:if>
    </xsl:template>

    <xsl:template match="exemplar:feature[@code='10.1601.fr.16S']|exemplar:feature[@code='10.1601.fr.chromosome']|exemplar:feature[@code='10.1601.fr.plasmid']|exemplar:feature[@code='10.1601.fr.phage']" mode="submenu-feature-information">
        <item type="link">
            <external-link>
                <xsl:attribute name="url">
                  <xsl:choose>
                    <xsl:when test="@url"><xsl:value-of select="@url" /></xsl:when>
                    <xsl:otherwise>
                      <xsl:text>https://www.ncbi.nlm.nih.gov/nuccore/</xsl:text><xsl:value-of select="@id" />
<!--
                      <xsl:for-each select="exemplar:range">
                          <xsl:choose><xsl:when test="position()=1"><xsl:text>?</xsl:text></xsl:when><xsl:otherwise><xsl:text>&amp;</xsl:text></xsl:otherwise></xsl:choose>
                          <xsl:text>from=</xsl:text><xsl:value-of select="@from" />
                          <xsl:text>&amp;to=</xsl:text><xsl:value-of select="@to" />
                      </xsl:for-each>
-->
                      <xsl:if test="exemplar:range">
                          <xsl:text>?</xsl:text>
                          <xsl:text>from=</xsl:text><xsl:value-of select="exemplar:range[position()=1]/@from" />
                          <xsl:text>&amp;to=</xsl:text><xsl:value-of select="exemplar:range[position()=last()]/@to" />
                      </xsl:if>
                    </xsl:otherwise>
                  </xsl:choose>
                </xsl:attribute>
                <xsl:value-of select="@description" /><xsl:if test="sequence-note"> (<xsl:value-of select="note" />)</xsl:if><xsl:text> (GenBank </xsl:text><xsl:value-of select="@id" />
                <xsl:for-each select="exemplar:range">
                    <xsl:if test="position()!=1"><xsl:text>,</xsl:text></xsl:if>
                    <xsl:text> </xsl:text><xsl:value-of select="@from" /><xsl:text>-</xsl:text><xsl:value-of select="@to" />
                </xsl:for-each>
                <xsl:text>)</xsl:text>
            </external-link>
        </item>
    </xsl:template>

    <xsl:template match="exemplar:feature[@code='10.1601.fr.assembly']" mode="submenu-feature-information">
        <item type="link">
            <external-link>
                <xsl:attribute name="url">
                    <xsl:text>https://www.ncbi.nlm.nih.gov/assembly/</xsl:text><xsl:value-of select="@id" />
                </xsl:attribute>
                <xsl:value-of select="@description" /><xsl:text> </xsl:text><xsl:value-of select="@id" />
            </external-link>
        </item>
    </xsl:template>

    <xsl:template match="exemplar:feature[@code='10.1601.fr.project']" mode="submenu-feature-information">
        <item type="link">
            <external-link>
                <xsl:attribute name="url">
                    <xsl:text>https://www.ncbi.nlm.nih.gov/genomeprj/</xsl:text><xsl:value-of select="@id" />
                </xsl:attribute>
                <xsl:value-of select="@description" /><xsl:text> </xsl:text><xsl:value-of select="@id" />
            </external-link>
        </item>
    </xsl:template>

    <xsl:template match="exemplar:feature[@code='10.1601.fr.gold']" mode="submenu-feature-information">
        <item type="link">
            <external-link>
                <xsl:attribute name="url">
                    <xsl:text>https://gold.jgi.doe.gov/resolver?id=</xsl:text><xsl:value-of select="@id" />
                </xsl:attribute>
                <xsl:value-of select="@description" /><xsl:text> </xsl:text><xsl:value-of select="@id" />
            </external-link>
        </item>
    </xsl:template>

    <xsl:template match="exemplar:feature" mode="submenu-feature-information">
        <item type="link"><xsl:value-of select="@id" /></item>
    </xsl:template>

    <xsl:template match="reference:bibliography" mode="submenu-bibliography">
        <submenu type="info">
            <title>
                <item type="citation">Bibliography</item>
            </title>
            <xsl:apply-templates select="reference:reference/reference:citation" mode="submenu-infopanel-reference-item">
                <xsl:sort data-type="number" order="descending" select="reference:year/text()" />
            </xsl:apply-templates>
        </submenu>
    </xsl:template>

    <xsl:template match="reference:reference" mode="submenu-reference">
        <xsl:param name="title" />
        <submenu type="info">
            <title>
                <item type="citation"><xsl:value-of select="$title" /></item>
            </title>
            <xsl:apply-templates select="reference:citation" mode="submenu-infopanel-reference-item" />
        </submenu>
    </xsl:template>

    <xsl:template match="reference:citation" mode="submenu-infopanel-reference-item">
        <content type="bibliography"><xsl:apply-templates select="." mode="text-citation-full" /></content>
    </xsl:template>

    <xsl:template match="reference:citation" mode="submenu-infopanel-reference-menu">
        <xsl:param name="title" />
        <submenu type="info">
            <title>
                <item type="citation">
                    <xsl:choose>
                        <xsl:when test="$title"><xsl:value-of select="$title" /></xsl:when>
                        <xsl:otherwise><xsl:apply-templates select="." mode="text-citation-short" /></xsl:otherwise>
                    </xsl:choose>
                </item>
            </title>
            <content><xsl:apply-templates select="." mode="text-citation-full" /></content>
        </submenu>
    </xsl:template>

    <xsl:template match="reference:citation[@citation-type='journal']" mode="text-citation-short">
        <xsl:apply-templates select="reference:authors" mode="author-string-primary" />
        <xsl:text> (</xsl:text>
        <xsl:value-of select="reference:year" />
        <xsl:text>) </xsl:text>
        <xsl:choose>
            <xsl:when test="reference:abbrev">
                <xsl:value-of select="reference:abbrev" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="reference:source" />
            </xsl:otherwise>
        </xsl:choose>
        <xsl:text> </xsl:text>
        <xsl:if test="reference:volume">
            <xsl:value-of select="reference:volume" />
            <xsl:text>:</xsl:text>
        </xsl:if>
        <xsl:if test="reference:issue">
            <xsl:text>(</xsl:text><xsl:value-of select="reference:issue" /><xsl:text>)</xsl:text>
        </xsl:if>
        <xsl:value-of select="reference:fpage" />
        <xsl:if test="reference:lpage">
            <xsl:text>&#8211;</xsl:text>
            <xsl:value-of select="reference:lpage" />
        </xsl:if>
    </xsl:template>

    <xsl:template match="reference:citation[@citation-type='book']" mode="text-citation-short">
        <xsl:choose>
            <xsl:when test="reference:abbrev">
                <xsl:value-of select="reference:abbrev" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="reference:source" />
            </xsl:otherwise>
        </xsl:choose>
        <xsl:if test="reference:edition">
            <xsl:text>, </xsl:text>
            <xsl:apply-templates select="reference:edition" mode="format-edition" />
        </xsl:if>
        <xsl:if test="reference:volume">
            <xsl:text>, Vol. </xsl:text>
            <xsl:value-of select="reference:volume" />
        </xsl:if>
        <xsl:if test="reference:year">
            <xsl:text>, </xsl:text>
            <xsl:value-of select="reference:year" />
        </xsl:if>
    </xsl:template>

    <xsl:template match="reference:citation[@citation-type='thesis']" mode="text-citation-short">
        <xsl:if test="reference:authors">
            <xsl:apply-templates select="reference:authors" mode="author-string-full" />
            <xsl:text>.</xsl:text>
        </xsl:if>
        <xsl:if test="reference:label">
            <xsl:text>, </xsl:text>
            <xsl:value-of select="reference:label" />
            <xsl:if test="reference:year">
                <xsl:text> </xsl:text>
                <xsl:value-of select="reference:year" />
            </xsl:if>
        </xsl:if>
    </xsl:template>

    <xsl:template match="reference:citation[@citation-type='journal']" mode="text-citation-full">
        <xsl:apply-templates select="reference:authors" mode="author-string-full" />
        <xsl:text>. </xsl:text>
        <xsl:if test="reference:article-title">
            <xsl:value-of select="reference:article-title" />
            <xsl:if test="substring(reference:article-title, string-length(reference:article-title)) != '.'">.</xsl:if>
            <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:choose>
            <xsl:when test="reference:abbrev">
                <i><xsl:value-of select="reference:abbrev" /></i>
            </xsl:when>
            <xsl:otherwise>
                <i><xsl:value-of select="reference:source" /></i>
            </xsl:otherwise>
        </xsl:choose>
        <xsl:text> </xsl:text>
        <xsl:value-of select="reference:year" />
        <xsl:text>; </xsl:text>
        <xsl:if test="reference:volume">
            <b><xsl:value-of select="reference:volume" /></b>
            <xsl:text>:</xsl:text>
        </xsl:if>
        <xsl:if test="reference:issue">
            <xsl:text>(</xsl:text><xsl:value-of select="reference:issue" /><xsl:text>)</xsl:text>
        </xsl:if>
        <xsl:value-of select="reference:fpage" />
        <xsl:if test="reference:lpage">
            <xsl:text>&#8211;</xsl:text>
            <xsl:value-of select="reference:lpage" />
        </xsl:if>
        <xsl:text>.</xsl:text>
        <xsl:for-each select="reference:pub-id">
            <xsl:text> </xsl:text>
            <xsl:choose>
                <xsl:when test="@pub-id-type='doi'"></xsl:when>
                <xsl:otherwise><xsl:text>[</xsl:text></xsl:otherwise>
            </xsl:choose>
            <external-link>
                <xsl:attribute name="label"></xsl:attribute>
                <xsl:attribute name="url">
                    <xsl:choose>
                        <xsl:when test="@pub-id-type='doi'"><xsl:text>https://doi.org/</xsl:text><xsl:value-of select="." /></xsl:when>
                        <xsl:when test="@pub-id-type='pmid'"><xsl:text>https://www.ncbi.nlm.nih.gov/pubmed/</xsl:text><xsl:value-of select="." /></xsl:when>
                        <xsl:otherwise></xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
                <xsl:choose>
                    <xsl:when test="@pub-id-type='doi'"><xsl:text>https://doi.org/</xsl:text><xsl:value-of select="." /></xsl:when>
                    <xsl:when test="@pub-id-type='pmid'">PubMed</xsl:when>
                    <xsl:otherwise><xsl:value-of select="." /></xsl:otherwise>
                </xsl:choose>
            </external-link>
            <xsl:choose>
                <xsl:when test="@pub-id-type='doi'"></xsl:when>
                <xsl:otherwise><xsl:text>]</xsl:text></xsl:otherwise>
            </xsl:choose>
            <xsl:if test="position()=last()"><xsl:text>.</xsl:text></xsl:if>
        </xsl:for-each>
    </xsl:template>

<!--
    author, chapter title, In: editor name(s), Ed(s), book title, publisher, city, year, page(s)

    <edb>10. Garrity GM, Bell JA, Lilburn T. Class III. Gammaproteobacteria class. nov. In: DJ Brenner, NR Krieg, JT Staley, Garrity GM (eds), Bergey's Manual of Systematic Bacteriology, second edition, vol. 2 (The Proteobacteria), part B (The Gammaproteobacteria), Springer, New York, 2005, p. 1.</edb>
    <edb>11. Garrity GM, Bell JA, Lilburn T. Order VIII. Oceanospirillales ord. nov. In: DJ Brenner, NR Krieg, JT Staley, Garrity GM (eds), Bergey's Manual of Systematic Bacteriology, second edition, vol. 2 (The Proteobacteria), part B (The Gammaproteobacteria), Springer, New York, 2005, p. 270.</edb>
-->

    <xsl:template match="reference:citation[@citation-type='book']" mode="text-citation-full">
        <xsl:if test="reference:authors">
            <xsl:apply-templates select="reference:authors" mode="author-string-full" />
            <xsl:text>.</xsl:text>
        </xsl:if>
        <xsl:if test="reference:article-title">
            <xsl:if test="reference:authors">
                <xsl:text> </xsl:text>
            </xsl:if>
            <xsl:value-of select="reference:article-title" />
            <xsl:if test="substring(reference:article-title, string-length(reference:article-title)) != '.'">.</xsl:if>
        </xsl:if>
        <xsl:if test="reference:editors">
            <xsl:if test="reference:authors or reference:article-title">
                <xsl:text> </xsl:text>
            </xsl:if>
            <i>In:</i>
            <xsl:text> </xsl:text>
            <xsl:apply-templates select="reference:editors" mode="author-string-full" />
            <xsl:text> (ed</xsl:text>
            <xsl:if test="count(reference:editors/reference:person-name) &gt; 1">
                <xsl:text>s</xsl:text>
            </xsl:if>
            <xsl:text>)</xsl:text>
            <xsl:if test="reference:source or reference:publisher-name or reference:publisher-loc or reference:year or reference:fpage">
                <xsl:text>,</xsl:text>
            </xsl:if>
        </xsl:if>
        <xsl:if test="reference:source">
            <xsl:text> </xsl:text>
            <xsl:choose>
                <xsl:when test="reference:abbrev">
                    <xsl:value-of select="reference:abbrev" />
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="reference:source" />
                </xsl:otherwise>
            </xsl:choose>
            <xsl:if test="reference:edition">
                <xsl:text>, </xsl:text>
                <xsl:apply-templates select="reference:edition" mode="format-edition" />
            </xsl:if>
            <xsl:if test="reference:volume">
                <xsl:text>, Volume </xsl:text>
                <xsl:value-of select="reference:volume" />
            </xsl:if>
            <xsl:if test="reference:publisher-name or reference:publisher-loc or reference:year or reference:fpage">
                <xsl:text>,</xsl:text>
            </xsl:if>
        </xsl:if>
        <xsl:if test="reference:publisher-name">
            <xsl:text> </xsl:text>
            <xsl:value-of select="reference:publisher-name" />
            <xsl:if test="reference:publisher-loc or reference:year or reference:fpage">
                <xsl:text>,</xsl:text>
            </xsl:if>
        </xsl:if>
        <xsl:if test="reference:publisher-loc">
            <xsl:text> </xsl:text>
            <xsl:value-of select="reference:publisher-loc" />
            <xsl:if test="reference:year or reference:fpage">
                <xsl:text>,</xsl:text>
            </xsl:if>
        </xsl:if>
        <xsl:if test="reference:year">
            <xsl:text> </xsl:text>
            <xsl:value-of select="reference:year" />
            <xsl:if test="reference:fpage">
                <xsl:text>,</xsl:text>
            </xsl:if>
        </xsl:if>
        <xsl:if test="reference:fpage">
            <xsl:text> p. </xsl:text>
            <xsl:value-of select="reference:fpage" />
            <xsl:if test="reference:lpage">
                <xsl:text>&#8211;</xsl:text>
                <xsl:value-of select="reference:lpage" />
            </xsl:if>
        </xsl:if>
        <xsl:text>.</xsl:text>
    </xsl:template>

<!--
    Iyer, Naresh Sundaram. "A Family of Dominance Filters for Multiple Criteria 
    Decision Making: Choosing the Right Filter for a Decision Situation."  
    Ph.D. diss., Ohio State University, 2001.
-->
    <xsl:template match="reference:citation[@citation-type='thesis']" mode="text-citation-full">
        <xsl:if test="reference:authors">
            <xsl:apply-templates select="reference:authors" mode="author-string-full" />
            <xsl:text>.</xsl:text>
        </xsl:if>
        <xsl:if test="reference:article-title">
            <xsl:if test="reference:authors">
                <xsl:text> </xsl:text>
            </xsl:if>
            <xsl:text>"</xsl:text>
            <xsl:value-of select="reference:article-title" />
            <xsl:if test="substring(reference:article-title, string-length(reference:article-title)) != '.'">.</xsl:if>
            <xsl:text>"</xsl:text>
        </xsl:if>
        <xsl:if test="reference:label">
            <xsl:text> </xsl:text>
            <xsl:value-of select="reference:label" />
            <xsl:if test="reference:institution or reference:year">
                <xsl:text>,</xsl:text>
            </xsl:if>
        </xsl:if>
        <xsl:if test="reference:institution">
            <xsl:text> </xsl:text>
            <xsl:value-of select="reference:institution" />
            <xsl:if test="reference:year">
                <xsl:text>,</xsl:text>
            </xsl:if>
        </xsl:if>
        <xsl:if test="reference:year">
            <xsl:text> </xsl:text>
            <xsl:value-of select="reference:year" />
            <xsl:if test="reference:fpage">
                <xsl:text>,</xsl:text>
            </xsl:if>
        </xsl:if>
        <xsl:if test="reference:fpage">
            <xsl:text> p. </xsl:text>
            <xsl:value-of select="reference:fpage" />
            <xsl:if test="reference:lpage">
                <xsl:text>-</xsl:text>
                <xsl:value-of select="reference:lpage" />
            </xsl:if>
        </xsl:if>
        <xsl:text>.</xsl:text>
    </xsl:template>

    <xsl:template match="reference:edition" mode="format-edition">
        <xsl:choose>
            <xsl:when test="text()='1'">
                <xsl:text>First Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='2'">
                <xsl:text>Second Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='3'">
                <xsl:text>Third Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='4'">
                <xsl:text>Fourth Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='5'">
                <xsl:text>Fifth Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='6'">
                <xsl:text>Sixth Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='7'">
                <xsl:text>Seventh Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='8'">
                <xsl:text>Eighth Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='9'">
                <xsl:text>Ninth Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='10'">
                <xsl:text>Tenth Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='11'">
                <xsl:text>Eleventh Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='12'">
                <xsl:text>Twelfth Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='13'">
                <xsl:text>Thirteenth Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='14'">
                <xsl:text>Fourteenth Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='15'">
                <xsl:text>Fifteenth Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='16'">
                <xsl:text>Sixteenth Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='17'">
                <xsl:text>Seventeenth Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='18'">
                <xsl:text>Eighteenth Edition</xsl:text>
            </xsl:when>
            <xsl:when test="text()='19'">
                <xsl:text>Ninteenth Edition</xsl:text>
            </xsl:when>
            <xsl:otherwise>
                <xsl:text>Edition </xsl:text>
                <xsl:value-of select="text()" />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="reference:authors|reference:editors" mode="author-string-primary">
        <xsl:choose>
            <xsl:when test="count(reference:person-name) = 1">
                <xsl:apply-templates select="reference:person-name[1]" mode="last" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="reference:person-name[1]" mode="last" />
                <xsl:text> </xsl:text><em>et al.</em>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="reference:authors|reference:editors" mode="author-string-condensed">
        <xsl:choose>
            <xsl:when test="count(reference:person-name) = 1">
                <xsl:apply-templates select="reference:person-name[1]" mode="last-first" />
            </xsl:when>
            <xsl:when test="count(reference:person-name) = 2">
                <xsl:apply-templates select="reference:person-name[1]" mode="last-first" />
                <xsl:text> and </xsl:text>
                <xsl:apply-templates select="reference:person-name[2]" mode="last-first" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:apply-templates select="reference:person-name[1]" mode="last-first" />
                <xsl:text> </xsl:text><em>et al.</em>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

    <xsl:template match="reference:authors|reference:editors" mode="author-string-full">
        <xsl:for-each select="reference:person-name">
            <xsl:if test="position() != 1">
                <xsl:text>, </xsl:text>
            </xsl:if>
            <xsl:choose>
                <xsl:when test="position()=1 and name(..)='authors'"><b><xsl:apply-templates select="." mode="last-first" /></b></xsl:when>
                <xsl:otherwise><xsl:apply-templates select="." mode="last-first" /></xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="reference:person-name" mode="last-first">
        <xsl:value-of select="reference:surname" />
        <xsl:if test="reference:given-names/text()">
            <xsl:text> </xsl:text>
            <xsl:value-of select="translate(reference:given-names, '.', '')" />
        </xsl:if>
        <xsl:if test="reference:suffix">
            <xsl:text> </xsl:text>
            <xsl:value-of select="reference:suffix" />
        </xsl:if>
    </xsl:template>

    <xsl:template match="reference:person-name" mode="first-last">
        <xsl:if test="reference:given-names/text()">
            <xsl:value-of select="reference:given-names" />
            <xsl:text> </xsl:text>
        </xsl:if>
        <xsl:value-of select="reference:surname" />
        <xsl:if test="reference:suffix">
            <xsl:text> </xsl:text>
            <xsl:value-of select="reference:suffix" />
        </xsl:if>
    </xsl:template>

    <xsl:template match="reference:person-name" mode="last">
        <xsl:value-of select="reference:surname" />
    </xsl:template>

    <xsl:template match="name:name" mode="abstract-link">
        <item type="link">
            <external-link>
                <xsl:attribute name="url">
                    <xsl:text>https://doi.org/</xsl:text><xsl:value-of select="common:nomenclature/common:name-status-group/common:identifier/@doi" />
                </xsl:attribute>
                <xsl:text>Nomenclature Abstract</xsl:text>
            </external-link>
        </item>
    </xsl:template>

    <xsl:template match="name:synonym" mode="abstract-link">
        <item type="link">
            <external-link>
                <xsl:attribute name="url">
                    <xsl:text>https://doi.org/</xsl:text><xsl:value-of select="common:name-status-group/common:identifier/@doi" />
                </xsl:attribute>
                <xsl:value-of select="common:name-status-group/common:identifier" />
            </external-link>
        </item>
    </xsl:template>

    <xsl:template match="taxon:taxon" mode="abstract-link">
        <xsl:param name="label" />
        <item type="link">
            <external-link>
                <xsl:attribute name="url">
                    <xsl:text>https://doi.org/</xsl:text><xsl:value-of select="@doi" />
                </xsl:attribute>
                <xsl:choose>
                  <xsl:when test="$label"><xsl:value-of select="$label" /></xsl:when>
                  <xsl:otherwise>Taxonomic Abstract</xsl:otherwise>
                </xsl:choose>
            </external-link>
        </item>
    </xsl:template>

    <xsl:template match="exemplar:exemplar" mode="abstract-link">
        <xsl:variable name="type-exemplar-doi" select="../../common:nomenclatural-type/@nomenclatural-type-exemplar" />
        <item type="link">
            <external-link>
                <xsl:attribute name="url">
                    <xsl:text>https://doi.org/</xsl:text><xsl:value-of select="@doi" />
                </xsl:attribute>
                <xsl:if test="not(@doi=$type-exemplar-doi)">Non-</xsl:if>
                <xsl:text>Type Strain Abstract</xsl:text>
            </external-link>
        </item>
    </xsl:template>

    <xsl:template match="name:name" mode="submenu-help">
        <submenu type="info">
            <title>
                <item type="help">About the Guide</item>
            </title>
            <content>
                <list>
                    <list-item>The <external-link label="Guide" url="https://www.namesforlife.com/guide">Guide</external-link> is maintained by <external-link label="NamesforLife, LLC" url="https://namesforlife.com">NamesforLife, LLC</external-link>.</list-item>
                    <list-item>The information presented in this menu was generated from a <xsl:value-of select="$snapshot" /> snapshot of a professionally curated database of <external-link label="Prokaryotic Nomenclature and Taxonomy" url="https://doi.org/10.1601/about">Prokaryotic Nomenclature and Taxonomy</external-link>.</list-item>
                    <list-item type="footer"><xsl:value-of select="$build" /></list-item>
                </list>
            </content>
        </submenu>
    </xsl:template>

    <!-- The rest of these templates are copied verbatim from the Name Abstract XSL. -->

  <!-- Nomenclatural History -->
  <xsl:template match="name:name" mode="monograph-entry-history">
        <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. -->
          <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>
              <xsl:text>Approved Lists of Bacterial Names</xsl:text>
            </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" />

  </xsl:template>

  <!-- Nomenclatural History: Incertae sedis -->
  <xsl:template match="name:name" mode="history-incertae">
    <xsl:variable name="name" select="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'">conserved</xsl:when>
        <xsl:when test="name:opinion/@opinion-type='Rejected'">rejected</xsl:when>
        <xsl:when test="name:opinion/@opinion-type='OtherObservation'">affected</xsl:when>
        <xsl:otherwise>cited</xsl:otherwise>
    </xsl:choose>
    <xsl:text> by Judicial Opinion </xsl:text>
    <xsl:value-of select="name:opinion/@opinion-number" />
    <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>
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
        <xsl:text> corrected this name from </xsl:text>
      </xsl:otherwise>
    </xsl:choose>
    <i><xsl:value-of select="name:correction/@from-name" /></i>
    <xsl:text> (sic) to </xsl:text>
    <i><xsl:value-of select="name:correction/@to-name" /></i>
    <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> 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>
    <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authority" />
    <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>
    <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    <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> 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: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>
    <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authority" />
    <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>
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
        <xsl:text> published an emended description of this </xsl:text>
        <xsl:value-of select="/name:name/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>
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
        <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>
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
        <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>
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
        <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>
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
        <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 -->
  <xsl:template match="name:event[@type='validation']" mode="history">
    <xsl:choose>
      <xsl:when test="../name:event[@type='effective-publication']/@reference=@reference"></xsl:when> <!-- Bug 11: 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" />
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authority" />
        <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 appeared on </xsl:text>
    <xsl:text>Validation List No. </xsl:text>
    <xsl:value-of select="@list-number" />
    <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>
    <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" />
    <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>

  <!-- 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>
        <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
        <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>
        <i><xsl:value-of select="common:name-status-group/common:identifier" /></i>
        <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>
        <i><xsl:value-of select="common:name-status-group/common:identifier" /></i>
        <xsl:text>.</xsl:text>
    </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>
    <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    <xsl:text> established </xsl:text>
    <i><xsl:value-of select="/name:name/common:name-status-group/common:identifier" /></i>
    <xsl:text> as an earlier homotypic synonym of </xsl:text>
    <i><xsl:value-of select="common:name-status-group/common:identifier" /></i>
    <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>
    <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    <xsl:text> established </xsl:text>
    <i><xsl:value-of select="/name:name/common:name-status-group/common:identifier" /></i>
    <xsl:text> as a later homotypic synonym of </xsl:text>
    <i><xsl:value-of select="common:name-status-group/common:identifier" /></i>
    <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>
    <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    <xsl:text> established this name as an earlier heterotypic synonym of </xsl:text>
    <i><xsl:value-of select="common:name-status-group/common:identifier" /></i>
    <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>
    <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    <xsl:text> established this name as a later heterotypic synonym of </xsl:text>
    <i><xsl:value-of select="common:name-status-group/common:identifier" /></i>
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <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> </xsl:text>
    <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    <xsl:text> established </xsl:text>
    <i><xsl:value-of select="/name:name/common:name-status-group/common:identifier" /></i>
    <xsl:text> as the basonym of </xsl:text>
    <i><xsl:value-of select="common:name-status-group/common:identifier" /></i>
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
<!--    <xsl:text> via strain </xsl:text> -->
    <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>
    <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    <xsl:text> established </xsl:text>
    <i><xsl:value-of select="common:name-status-group/common:identifier" /></i>
    <xsl:text> as the basonym of </xsl:text>
    <i><xsl:value-of select="/name:name/common:name-status-group/common:identifier" /></i>
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
<!--    <xsl:text> via strain </xsl:text> -->
    <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>
    <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    <xsl:text> transferred the members of </xsl:text>
    <i><xsl:value-of select="common:name-status-group/common:identifier" /></i>
    <xsl:text> into this </xsl:text>
    <xsl:apply-templates select="/name:name/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>
    <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    <xsl:text> transferred the members of this </xsl:text>
    <xsl:apply-templates select="/name:name/common:name-status-group/common:identifier/@rank" />
    <xsl:text> into </xsl:text>
    <i><xsl:value-of select="common:name-status-group/common:identifier" /></i>
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <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>
    <i><xsl:value-of select="common:name-status-group/common:identifier" /></i>
    <xsl:text> was created via Rule 40d (formerly Rule 46</xsl:text>
    <xsl:text>) of the International Code of Nomenclature of Bacteria following the proposal of </xsl:text>
    <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    <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>
    <i><xsl:value-of select="/name:name/common:name-status-group/common:identifier" /></i>
    <xsl:text> was created via Rule 40d (formerly Rule 46</xsl:text>
    <xsl:text>) of the International Code of Nomenclature of Bacteria following the proposal of </xsl:text>
    <xsl:apply-templates select="/name:name/reference:bibliography/reference:reference[@id=$refid]" mode="authors" />
    <xsl:text> in </xsl:text>
    <xsl:value-of select="@date" />
    <xsl:text>.</xsl:text>
  </xsl:template>

  <!-- Citation of Authors -->
  <xsl:template match="reference:reference" mode="authors">
    <xsl:apply-templates select="reference:citation" mode="authors" />
  </xsl:template>

  <!-- Citation of Authors -->
  <xsl:template match="reference:citation" mode="authors">
    <xsl:apply-templates select="reference:authors" mode="author-string-authority" />
  </xsl:template>

  <!-- Citation of Authority -->
  <xsl:template match="reference:reference" mode="authority">
    <xsl:apply-templates select="reference:citation" mode="authority" />
  </xsl:template>

  <!-- Citation of Authority -->
  <xsl:template match="reference:citation" mode="authority">
    <xsl:apply-templates select="reference:authors" mode="author-string-authority" />
    <xsl:text> </xsl:text>
    <xsl:apply-templates select="reference:year" />
  </xsl:template>

  <xsl:template match="reference:authors|reference:editors" mode="author-string-authority">
    <xsl:choose>
      <xsl:when test="count(reference:person-name) = 1">
        <xsl:apply-templates select="reference:person-name[1]" mode="last" />
      </xsl:when>
      <xsl:when test="count(reference:person-name) = 2">
        <xsl:apply-templates select="reference:person-name[1]" mode="last" />
        <xsl:text> and </xsl:text>
        <xsl:apply-templates select="reference:person-name[2]" mode="last" />
      </xsl:when>
      <xsl:otherwise>
        <xsl:apply-templates select="reference:person-name[1]" mode="last" />
        <xsl:text> </xsl:text><em>et al.</em>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>
