</xsl:if>
<xsl:call-template name="index.titlepage"/>
- <xsl:apply-templates/>
+ <xsl:choose>
+ <xsl:when test="indexdiv">
+ <xsl:apply-templates/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:apply-templates select="*[not(self::indexentry)]"/>
+ <!-- Because it's actually valid for Index to have neither any -->
+ <!-- Indexdivs nor any Indexentries, we need to check and make -->
+ <!-- sure that at least one Indexentry exists, and generate a -->
+ <!-- wrapper dl if there is at least one; otherwise, do nothing. -->
+ <xsl:if test="indexentry">
+ <!-- The indexentry template assumes a parent dl wrapper has -->
+ <!-- been generated; for Indexes that have Indexdivs, the dl -->
+ <!-- wrapper is generated by the indexdiv template; however, -->
+ <!-- for Indexes that lack Indexdivs, if we don't generate a -->
+ <!-- dl here, HTML output will not be valid. -->
+ <dl>
+ <xsl:apply-templates select="indexentry"/>
+ </dl>
+ </xsl:if>
+ </xsl:otherwise>
+ </xsl:choose>
<xsl:if test="count(indexentry) = 0 and count(indexdiv) = 0">
<xsl:call-template name="generate-index">