commit f1094c3a9abcd6b3d23b85262a963f42ef9a9929
Author: Alexander Lakhin <exclusion@gmail.com>
Date:   Mon Nov 21 23:49:16 2016 +0300

    Add TOC to sect1
    
    As in spi-memory.html:
     44.3. Memory Management
    ->
     44.3. Memory Management
       Table of Contents
       SPI_palloc &mdash; allocate memory in the upper executor context
       SPI_repalloc &mdash; reallocate memory in the upper executor context

diff --git a/doc/src/sgml/stylesheet-imports-xhtml.xsl b/doc/src/sgml/stylesheet-imports-xhtml.xsl
new file mode 100644
index 0000000..4139d1d
--- /dev/null
+++ b/doc/src/sgml/stylesheet-imports-xhtml.xsl
@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="ASCII"?>
+<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml" version="1.0">
+
+<!-- Add TOC to sect1 -->
+
+<!-- from xhtml/sections.xsl -->
+
+<xsl:template match="sect1">
+  <xsl:call-template name="id.warning"/>
+
+  <xsl:element name="{$div.element}" namespace="http://www.w3.org/1999/xhtml">
+    <xsl:call-template name="common.html.attributes">
+      <xsl:with-param name="inherit" select="1"/>
+    </xsl:call-template>
+    <xsl:call-template name="id.attribute">
+      <xsl:with-param name="conditional" select="0"/>
+    </xsl:call-template>
+
+    <xsl:choose>
+      <xsl:when test="@renderas = 'sect2'">
+        <xsl:call-template name="sect2.titlepage"/>
+      </xsl:when>
+      <xsl:when test="@renderas = 'sect3'">
+        <xsl:call-template name="sect3.titlepage"/>
+      </xsl:when>
+      <xsl:when test="@renderas = 'sect4'">
+        <xsl:call-template name="sect4.titlepage"/>
+      </xsl:when>
+      <xsl:when test="@renderas = 'sect5'">
+        <xsl:call-template name="sect5.titlepage"/>
+      </xsl:when>
+      <xsl:otherwise>
+        <xsl:call-template name="sect1.titlepage"/>
+      </xsl:otherwise>
+    </xsl:choose>
+
+    <xsl:variable name="toc.params">
+      <xsl:call-template name="find.path.params">
+        <xsl:with-param name="table" select="normalize-space($generate.toc)"/>
+      </xsl:call-template>
+    </xsl:variable>
+
+    <xsl:if test="contains($toc.params, 'toc')                   and ($generate.section.toc.level &gt;= 1 or count(refentry) &gt; 0)">
+      <xsl:call-template name="section.toc">
+        <xsl:with-param name="toc.title.p" select="contains($toc.params, 'title')"/>
+      </xsl:call-template>
+      <xsl:call-template name="section.toc.separator"/>
+    </xsl:if>
+    <xsl:apply-templates/>
+    <xsl:call-template name="process.chunk.footnotes"/>
+  </xsl:element>
+</xsl:template>
+
+</xsl:stylesheet>
diff --git a/doc/src/sgml/stylesheet.xsl b/doc/src/sgml/stylesheet.xsl
index 494dbf5..209afdf 100644
--- a/doc/src/sgml/stylesheet.xsl
+++ b/doc/src/sgml/stylesheet.xsl
@@ -9,6 +9,7 @@
                 exclude-result-prefixes="#default">
 
 <xsl:import href="http://docbook.sourceforge.net/release/xsl/current/xhtml/chunk.xsl"/>
+<xsl:import href="stylesheet-imports-xhtml.xsl" />
 <xsl:include href="stylesheet-common.xsl" />
 <xsl:include href="stylesheet-speedup-xhtml.xsl" />
 
@@ -482,4 +483,20 @@ Customization of header
   </xsl:if>
 </xsl:template>
 
+
+<!-- To use imported templates from stylesheet-imports-xhtml.xsl -->
+
+<!-- from xhtml/chunk-code.xsl -->
+
+<xsl:template match="sect1">
+  <xsl:choose>
+    <xsl:when test="$onechunk != 0 and parent::*">
+      <xsl:apply-imports/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:call-template name="process-chunk-element"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
 </xsl:stylesheet>
