From bb0fd616df072ab4325ed6e6d8ea6f527eb4227f Mon Sep 17 00:00:00 2001
From: Bob Stayton <bobs@sagehill.net>
Date: Thu, 19 Apr 2012 10:10:58 +0000
Subject: [PATCH] Add basic support for new <topic> element.

---
 xsl/common/common.xsl            |  2 +-
 xsl/common/entities.ent          |  4 +--
 xsl/common/gentext.xsl           |  2 +-
 xsl/common/labels.xsl            |  5 +++
 xsl/common/subtitles.xsl         |  1 +
 xsl/common/targets.xsl           |  4 +++
 xsl/common/titles.xsl            |  2 ++
 xsl/epub3/epub3-element-mods.xsl |  4 ++-
 xsl/fo/autotoc.xsl               |  3 +-
 xsl/fo/component.xsl             | 24 ++++++++++++++
 xsl/fo/index.xsl                 |  2 +-
 xsl/fo/titlepage.templates.xml   | 56 ++++++++++++++++++++++++++++++++
 xsl/fo/titlepage.xsl             |  3 ++
 xsl/fo/xref.xsl                  | 14 ++++++++
 xsl/html/autotoc.xsl             | 15 +++++++++
 xsl/html/changebars.xsl          |  1 +
 xsl/html/chunk-code.xsl          | 21 ++++++++++++
 xsl/html/chunk-common.xsl        | 10 ++++++
 xsl/html/chunktoc.xsl            |  4 +++
 xsl/html/component.xsl           | 46 ++++++++++++++++++++++++++
 xsl/html/titlepage.templates.xml | 30 +++++++++++++++++
 xsl/html/titlepage.xsl           |  3 ++
 xsl/html/xref.xsl                | 14 ++++++++
 xsl/template/titlepage.xsl       |  2 ++
 xsl/webhelp/xsl/webhelp.xsl      |  6 ++--
 25 files changed, 268 insertions(+), 10 deletions(-)

diff --git a/xsl/common/common.xsl b/xsl/common/common.xsl
index accb34344..6a80183d8 100644
--- a/xsl/common/common.xsl
+++ b/xsl/common/common.xsl
@@ -68,7 +68,7 @@ sectioninfo seglistitem segmentedlist seriesinfo set setindex setinfo
 shortcut sidebar simplelist simplesect spanspec step subject
 subjectset substeps synopfragment table tbody textobject tfoot tgroup
 thead tip toc tocchap toclevel1 toclevel2 toclevel3 toclevel4
-toclevel5 tocpart varargs variablelist varlistentry videodata
+toclevel5 tocpart topic varargs variablelist varlistentry videodata
 videoobject void warning subjectset
 
 classsynopsis
diff --git a/xsl/common/entities.ent b/xsl/common/entities.ent
index f9aaa4b97..fce53023b 100644
--- a/xsl/common/entities.ent
+++ b/xsl/common/entities.ent
@@ -28,7 +28,7 @@
 <!ENTITY secondary 'normalize-space(concat(secondary/@sortas, " ", secondary))'>
 <!ENTITY tertiary  'normalize-space(concat(tertiary/@sortas, " ", tertiary))'>
 
-<!ENTITY section   '(ancestor-or-self::set|ancestor-or-self::book|ancestor-or-self::part|ancestor-or-self::reference|ancestor-or-self::partintro|ancestor-or-self::chapter|ancestor-or-self::appendix|ancestor-or-self::preface|ancestor-or-self::article|ancestor-or-self::section|ancestor-or-self::sect1|ancestor-or-self::sect2|ancestor-or-self::sect3|ancestor-or-self::sect4|ancestor-or-self::sect5|ancestor-or-self::refentry|ancestor-or-self::refsect1|ancestor-or-self::refsect2|ancestor-or-self::refsect3|ancestor-or-self::simplesect|ancestor-or-self::bibliography|ancestor-or-self::glossary|ancestor-or-self::index|ancestor-or-self::webpage)[last()]'>
+<!ENTITY section   '(ancestor-or-self::set|ancestor-or-self::book|ancestor-or-self::part|ancestor-or-self::reference|ancestor-or-self::partintro|ancestor-or-self::chapter|ancestor-or-self::appendix|ancestor-or-self::preface|ancestor-or-self::article|ancestor-or-self::section|ancestor-or-self::sect1|ancestor-or-self::sect2|ancestor-or-self::sect3|ancestor-or-self::sect4|ancestor-or-self::sect5|ancestor-or-self::refentry|ancestor-or-self::refsect1|ancestor-or-self::refsect2|ancestor-or-self::refsect3|ancestor-or-self::simplesect|ancestor-or-self::bibliography|ancestor-or-self::glossary|ancestor-or-self::index|ancestor-or-self::webpage|ancestor-or-self::topic)[last()]'>
 
 <!ENTITY section.id 'generate-id(&section;)'>
 <!ENTITY sep '" "'>
@@ -64,4 +64,4 @@
                                 parent::refsynopsisdiv|parent::sect1|parent::sect2|parent::sect3|parent::sect4|
                                 parent::sect5|parent::section|parent::setindex|parent::sidebar|
                                 parent::simplesect|parent::taskprerequisites|parent::taskrelated|
-                                parent::tasksummary|parent::warning">
+                                parent::tasksummary|parent::warning|parent::topic">
diff --git a/xsl/common/gentext.xsl b/xsl/common/gentext.xsl
index 555bacffd..bfb5e3003 100644
--- a/xsl/common/gentext.xsl
+++ b/xsl/common/gentext.xsl
@@ -90,7 +90,7 @@
 </xsl:template>
 
 <xsl:template match="section|sect1|sect2|sect3|sect4|sect5|simplesect
-                     |bridgehead"
+                     |bridgehead|topic"
               mode="object.title.template">
   <xsl:variable name="is.numbered">
     <xsl:call-template name="label.this.section"/>
diff --git a/xsl/common/labels.xsl b/xsl/common/labels.xsl
index ccc91158e..d7b688ad2 100644
--- a/xsl/common/labels.xsl
+++ b/xsl/common/labels.xsl
@@ -382,6 +382,7 @@ element label.</para>
   <xsl:variable name="contsec"
                 select="(ancestor::section
                          |ancestor::simplesect
+                         |ancestor::topic
                          |ancestor::sect1
                          |ancestor::sect2
                          |ancestor::sect3
@@ -502,6 +503,10 @@ element label.</para>
   </xsl:choose>
 </xsl:template>
 
+<xsl:template match="topic" mode="label.markup">
+  <!-- topics are not numbered by default -->
+</xsl:template>
+
 <xsl:template match="qandadiv" mode="label.markup">
   <xsl:variable name="lparent" select="(ancestor::set
                                        |ancestor::book
diff --git a/xsl/common/subtitles.xsl b/xsl/common/subtitles.xsl
index d497daf68..deb691f21 100644
--- a/xsl/common/subtitles.xsl
+++ b/xsl/common/subtitles.xsl
@@ -154,6 +154,7 @@ subtitle of the element.
 <xsl:template match="section
                      |sect1|sect2|sect3|sect4|sect5
                      |refsect1|refsect2|refsect3
+                     |topic
                      |simplesect"
               mode="subtitle.markup">
   <xsl:param name="allow-anchors" select="'0'"/>
diff --git a/xsl/common/targets.xsl b/xsl/common/targets.xsl
index c3a32bcf9..c399441cb 100644
--- a/xsl/common/targets.xsl
+++ b/xsl/common/targets.xsl
@@ -230,6 +230,10 @@ document output.
   <xsl:call-template name="div"/>
 </xsl:template>
 
+<xsl:template match="topic" mode="olink.mode">
+  <xsl:call-template name="div"/>
+</xsl:template>
+
 <xsl:template match="bibliography|bibliodiv" mode="olink.mode">
   <xsl:call-template name="div"/>
 </xsl:template>
diff --git a/xsl/common/titles.xsl b/xsl/common/titles.xsl
index 6d2dcb3a8..e3025b12e 100644
--- a/xsl/common/titles.xsl
+++ b/xsl/common/titles.xsl
@@ -251,6 +251,7 @@ title of the element. This does not include the label.
 <xsl:template match="section
                      |sect1|sect2|sect3|sect4|sect5
                      |refsect1|refsect2|refsect3|refsection
+                     |topic
                      |simplesect"
               mode="title.markup">
   <xsl:param name="allow-anchors" select="0"/>
@@ -602,6 +603,7 @@ title of the element. This does not include the label.
 <xsl:template match="section
                      |sect1|sect2|sect3|sect4|sect5
                      |refsect1|refsect2|refsect3
+                     |topic
                      |simplesect"
               mode="titleabbrev.markup">
   <xsl:param name="allow-anchors" select="0"/>
diff --git a/xsl/epub3/epub3-element-mods.xsl b/xsl/epub3/epub3-element-mods.xsl
index 0c7707cea..68894325e 100644
--- a/xsl/epub3/epub3-element-mods.xsl
+++ b/xsl/epub3/epub3-element-mods.xsl
@@ -1645,6 +1645,7 @@ article  toc,title,figure,table,example,equation
 
 <xsl:template match="book|
                      article|
+                     topic|
                      part|
                      reference|
                      preface|
@@ -1698,6 +1699,7 @@ article  toc,title,figure,table,example,equation
                                 preceding::bibliography|
                                 preceding::appendix|
                                 preceding::article|
+                                preceding::topic|
                                 preceding::glossary|
                                 preceding::section[not(parent::partintro)]|
                                 preceding::sect1[not(parent::partintro)]|
@@ -1737,7 +1739,7 @@ article  toc,title,figure,table,example,equation
         <xsl:value-of select="$href"/>
       </xsl:attribute>
     </xsl:element>
-    <xsl:apply-templates select="book[parent::set]|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv[title]|setindex|index" mode="ncx"/>
+    <xsl:apply-templates select="book[parent::set]|part|reference|preface|chapter|bibliography|appendix|article|topic|glossary|section|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv[title]|setindex|index" mode="ncx"/>
   </xsl:element>
 
 </xsl:template>
diff --git a/xsl/fo/autotoc.xsl b/xsl/fo/autotoc.xsl
index 75b56b54c..e6aa17454 100644
--- a/xsl/fo/autotoc.xsl
+++ b/xsl/fo/autotoc.xsl
@@ -543,6 +543,7 @@
   <xsl:variable name="nodes" select="section|sect1
                                      |qandaset[$qanda.in.toc != 0]
                                      |simplesect[$simplesect.in.toc != 0]
+                                     |topic
                                      |refentry|appendix"/>
 
   <xsl:variable name="depth.from.context" select="count(ancestor::*)-count($toc-context/ancestor::*)"/>
@@ -717,7 +718,7 @@
   </xsl:if>
 </xsl:template>
 
-<xsl:template match="sect5|simplesect" mode="toc">
+<xsl:template match="sect5|simplesect|topic" mode="toc">
   <xsl:param name="toc-context" select="."/>
 
   <xsl:call-template name="toc.line">
diff --git a/xsl/fo/component.xsl b/xsl/fo/component.xsl
index 81dc7049b..43b04e114 100644
--- a/xsl/fo/component.xsl
+++ b/xsl/fo/component.xsl
@@ -907,5 +907,29 @@
 
 </xsl:template>
 
+<xsl:template match="topic">
+  <xsl:variable name="id">
+    <xsl:call-template name="object.id"/>
+  </xsl:variable>
+
+  <xsl:element name="fo:{$section.container.element}">
+    <xsl:attribute name="id"><xsl:value-of 
+                        select="$id"/></xsl:attribute>
+    <xsl:call-template name="topic.titlepage"/>
+    <xsl:apply-templates/>
+  </xsl:element>
+</xsl:template>
+
+<xsl:template match="/topic | book/topic" name="topic.page.sequence">
+  <xsl:variable name="master-reference">
+    <xsl:call-template name="select.pagemaster"/>
+  </xsl:variable>
+
+  <xsl:apply-templates select="." mode="page.sequence">
+    <xsl:with-param name="master-reference"
+                    select="$master-reference"/>
+  </xsl:apply-templates> 
+</xsl:template>
+
 </xsl:stylesheet>
 
diff --git a/xsl/fo/index.xsl b/xsl/fo/index.xsl
index ef9f40721..53a9b2949 100644
--- a/xsl/fo/index.xsl
+++ b/xsl/fo/index.xsl
@@ -472,7 +472,7 @@
 
   <xsl:variable name="parent" select="concat('|', local-name($parentnode), '|')"/>
 
-  <xsl:variable name="block.parents" select="'|answer|appendix|appendixinfo|article|articleinfo|bibliodiv|bibliography|bibliographyinfo|blockinfo|blockquote|bookinfo|callout|caution|chapter|chapterinfo|dedication|example|figure|formalpara|funcsynopsisinfo|glossary|glossaryinfo|glossdef|glossdiv|glossentry|highlights|important|index|indexinfo|info|informalexample|informalfigure|informaltable|itemizedlist|legalnotice|listitem|msgexplan|msgtext|note|objectinfo|orderedlist|partinfo|partintro|preface|prefaceinfo|procedure|qandadiv|qandaset|question|refentry|refentryinfo|referenceinfo|refmeta|refmiscinfo|refsect1|refsect1info|refsect2|refsect2info|refsect3|refsect3info|refsection|refsectioninfo|refsynopsisdiv|refsynopsisdivinfo|revdescription|screeninfo|sect1|sect1info|sect2|sect2info|sect3|sect3info|sect4|sect4info|sect5|sect5info|section|sectioninfo|setindex|setindexinfo|setinfo|sidebar|sidebarinfo|simplesect|step|table|task|taskprerequisites|taskrelated|tasksummary|tip|variablelist|warning|'"/>
+  <xsl:variable name="block.parents" select="'|answer|appendix|appendixinfo|article|articleinfo|bibliodiv|bibliography|bibliographyinfo|blockinfo|blockquote|bookinfo|callout|caution|chapter|chapterinfo|dedication|example|figure|formalpara|funcsynopsisinfo|glossary|glossaryinfo|glossdef|glossdiv|glossentry|highlights|important|index|indexinfo|info|informalexample|informalfigure|informaltable|itemizedlist|legalnotice|listitem|msgexplan|msgtext|note|objectinfo|orderedlist|partinfo|partintro|preface|prefaceinfo|procedure|qandadiv|qandaset|question|refentry|refentryinfo|referenceinfo|refmeta|refmiscinfo|refsect1|refsect1info|refsect2|refsect2info|refsect3|refsect3info|refsection|refsectioninfo|refsynopsisdiv|refsynopsisdivinfo|revdescription|screeninfo|sect1|sect1info|sect2|sect2info|sect3|sect3info|sect4|sect4info|sect5|sect5info|section|sectioninfo|setindex|setindexinfo|setinfo|sidebar|sidebarinfo|simplesect|step|table|task|taskprerequisites|taskrelated|tasksummary|tip|topic|variablelist|warning|'"/>
 
   <xsl:choose>
     <xsl:when test="contains($block.parents, $parent)">fo:block</xsl:when>
diff --git a/xsl/fo/titlepage.templates.xml b/xsl/fo/titlepage.templates.xml
index c928c835b..63606547b 100644
--- a/xsl/fo/titlepage.templates.xml
+++ b/xsl/fo/titlepage.templates.xml
@@ -650,6 +650,40 @@
   </t:titlepage-before>
 </t:titlepage>
 
+<t:titlepage t:element="section" t:wrapper="fo:block">
+  <t:titlepage-content t:side="recto">
+    <title
+	   margin-left="{$title.margin.left}"
+	   font-family="{$title.fontset}"/>
+    <subtitle
+	      font-family="{$title.fontset}"/>
+    <corpauthor/>
+    <authorgroup/>
+    <author/>
+    <othercredit/>
+    <releaseinfo/>
+    <copyright/>
+    <legalnotice/>
+    <pubdate/>
+    <revision/>
+    <revhistory/>
+    <abstract/>
+    <itermset/>
+  </t:titlepage-content>
+
+  <t:titlepage-content t:side="verso">
+  </t:titlepage-content>
+
+  <t:titlepage-separator>
+  </t:titlepage-separator>
+
+  <t:titlepage-before t:side="recto">
+  </t:titlepage-before>
+
+  <t:titlepage-before t:side="verso">
+  </t:titlepage-before>
+</t:titlepage>
+
 <t:titlepage t:element="sect1" t:wrapper="fo:block">
   <t:titlepage-content t:side="recto">
     <title
@@ -854,6 +888,28 @@
   </t:titlepage-before>
 </t:titlepage>
 
+<t:titlepage t:element="topic" t:wrapper="fo:block">
+  <t:titlepage-content t:side="recto">
+    <title
+	   margin-left="{$title.margin.left}"
+	   font-family="{$title.fontset}"/>
+    <subtitle
+	      font-family="{$title.fontset}"/>
+  </t:titlepage-content>
+
+  <t:titlepage-content t:side="verso">
+  </t:titlepage-content>
+
+  <t:titlepage-separator>
+  </t:titlepage-separator>
+
+  <t:titlepage-before t:side="recto">
+  </t:titlepage-before>
+
+  <t:titlepage-before t:side="verso">
+  </t:titlepage-before>
+</t:titlepage>
+
 <!-- ==================================================================== -->
 
   <t:titlepage t:element="bibliography" t:wrapper="fo:block">
diff --git a/xsl/fo/titlepage.xsl b/xsl/fo/titlepage.xsl
index 3219cadb5..c21149ed2 100644
--- a/xsl/fo/titlepage.xsl
+++ b/xsl/fo/titlepage.xsl
@@ -130,6 +130,9 @@
 <xsl:attribute-set name="simplesect.titlepage.verso.style"
                    use-attribute-sets="section.titlepage.verso.style"/>
 
+<xsl:attribute-set name="topic.titlepage.recto.style"/>
+<xsl:attribute-set name="topic.titlepage.verso.style"/>
+
 <xsl:attribute-set name="refnamediv.titlepage.recto.style"
                    use-attribute-sets="section.titlepage.recto.style"/>
 <xsl:attribute-set name="refnamediv.titlepage.verso.style"
diff --git a/xsl/fo/xref.xsl b/xsl/fo/xref.xsl
index 0e475dda0..62cd2f284 100644
--- a/xsl/fo/xref.xsl
+++ b/xsl/fo/xref.xsl
@@ -571,6 +571,19 @@
   <!-- What about "in Chapter X"? -->
 </xsl:template>
 
+<xsl:template match="topic" mode="xref-to">
+  <xsl:param name="referrer"/>
+  <xsl:param name="xrefstyle"/>
+  <xsl:param name="verbose" select="1"/>
+
+  <xsl:apply-templates select="." mode="object.xref.markup">
+    <xsl:with-param name="purpose" select="'xref'"/>
+    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
+    <xsl:with-param name="referrer" select="$referrer"/>
+    <xsl:with-param name="verbose" select="$verbose"/>
+  </xsl:apply-templates>
+</xsl:template>
+
 <xsl:template match="bridgehead" mode="xref-to">
   <xsl:param name="referrer"/>
   <xsl:param name="xrefstyle"/>
@@ -773,6 +786,7 @@
                                        |ancestor::sect3
                                        |ancestor::sect4
                                        |ancestor::sect5
+                                       |ancestor::topic
                                        |ancestor::refsection
                                        |ancestor::refsect1
                                        |ancestor::refsect2
diff --git a/xsl/html/autotoc.xsl b/xsl/html/autotoc.xsl
index 522febe13..e3f415d7e 100644
--- a/xsl/html/autotoc.xsl
+++ b/xsl/html/autotoc.xsl
@@ -190,6 +190,7 @@
     <xsl:with-param name="toc.title.p" select="$toc.title.p"/>
     <xsl:with-param name="nodes" select="section|sect1
                                          |simplesect[$simplesect.in.toc != 0]
+                                         |topic
                                          |refentry
                                          |article|bibliography|glossary
                                          |appendix|index
@@ -261,6 +262,7 @@
       <xsl:when test="local-name(.) = 'refsect1'">1</xsl:when>
       <xsl:when test="local-name(.) = 'refsect2'">2</xsl:when>
       <xsl:when test="local-name(.) = 'refsect3'">3</xsl:when>
+      <xsl:when test="local-name(.) = 'topic'">1</xsl:when>
       <xsl:when test="local-name(.) = 'simplesect'">
         <!-- sigh... -->
         <xsl:choose>
@@ -272,6 +274,7 @@
           <xsl:when test="local-name(..) = 'sect3'">4</xsl:when>
           <xsl:when test="local-name(..) = 'sect4'">5</xsl:when>
           <xsl:when test="local-name(..) = 'sect5'">6</xsl:when>
+          <xsl:when test="local-name(..) = 'topic'">2</xsl:when>
           <xsl:when test="local-name(..) = 'refsect1'">2</xsl:when>
           <xsl:when test="local-name(..) = 'refsect2'">3</xsl:when>
           <xsl:when test="local-name(..) = 'refsect3'">4</xsl:when>
@@ -409,6 +412,7 @@
     <xsl:with-param name="toc-context" select="$toc-context"/>
     <xsl:with-param name="nodes" select="section|sect1
                                          |simplesect[$simplesect.in.toc != 0]
+                                         |topic
                                          |refentry
                                          |glossary|bibliography|index
                                          |bridgehead[$bridgehead.in.toc != 0]"/>
@@ -481,6 +485,17 @@
   </xsl:call-template>
 </xsl:template>
 
+<xsl:template match="topic" mode="toc">
+  <xsl:param name="toc-context" select="."/>
+
+  <xsl:call-template name="subtoc">
+    <xsl:with-param name="toc-context" select="$toc-context"/>
+    <xsl:with-param name="nodes" select="section|refentry
+                                         |simplesect[$simplesect.in.toc != 0]
+                                         |bridgehead[$bridgehead.in.toc != 0]"/>
+  </xsl:call-template>
+</xsl:template>
+
 <xsl:template match="bridgehead" mode="toc">
   <xsl:param name="toc-context" select="."/>
 
diff --git a/xsl/html/changebars.xsl b/xsl/html/changebars.xsl
index 499a5fd22..80e681bb6 100644
--- a/xsl/html/changebars.xsl
+++ b/xsl/html/changebars.xsl
@@ -57,6 +57,7 @@ span.off     {  }
 		    or local-name(.) = 'sect3'
 		    or local-name(.) = 'sect4'
 		    or local-name(.) = 'sect5'
+		    or local-name(.) = 'topic'                    
 		    or local-name(.) = 'chapter'
 		    or local-name(.) = 'preface'
 		    or local-name(.) = 'itemizedlist'
diff --git a/xsl/html/chunk-code.xsl b/xsl/html/chunk-code.xsl
index 34867388f..cefe1478d 100644
--- a/xsl/html/chunk-code.xsl
+++ b/xsl/html/chunk-code.xsl
@@ -371,6 +371,25 @@
       </xsl:if>
     </xsl:when>
 
+    <xsl:when test="self::topic">
+      <xsl:choose>
+        <xsl:when test="/set">
+          <!-- in a set, make sure we inherit the right book info... -->
+          <xsl:apply-templates mode="recursive-chunk-filename" select="parent::*">
+            <xsl:with-param name="recursive" select="true()"/>
+          </xsl:apply-templates>
+        </xsl:when>
+        <xsl:otherwise>
+        </xsl:otherwise>
+      </xsl:choose>
+
+      <xsl:text>to</xsl:text>
+      <xsl:number level="any" format="01" from="book"/>
+      <xsl:if test="not($recursive)">
+        <xsl:value-of select="$html.ext"/>
+      </xsl:if>
+    </xsl:when>
+
     <xsl:otherwise>
       <xsl:text>chunk-filename-error-</xsl:text>
       <xsl:value-of select="name(.)"/>
@@ -508,6 +527,7 @@
 
 <xsl:template match="set|book|part|preface|chapter|appendix
                      |article
+                     |topic
                      |reference|refentry
                      |book/glossary|article/glossary|part/glossary
                      |book/bibliography|article/bibliography|part/bibliography
@@ -580,6 +600,7 @@
 <!-- ==================================================================== -->
 <xsl:template match="set|book|part|preface|chapter|appendix
                      |article
+                     |topic
                      |reference|refentry
                      |sect1|sect2|sect3|sect4|sect5
                      |section
diff --git a/xsl/html/chunk-common.xsl b/xsl/html/chunk-common.xsl
index caac35d4c..f0dc31f39 100644
--- a/xsl/html/chunk-common.xsl
+++ b/xsl/html/chunk-common.xsl
@@ -253,6 +253,7 @@
              |preceding::refentry[1]
              |preceding::colophon[1]
              |preceding::article[1]
+             |preceding::topic[1]
              |preceding::bibliography[parent::article or parent::book or parent::part][1]
              |preceding::glossary[parent::article or parent::book or parent::part][1]
              |preceding::index[$generate.index != 0]
@@ -266,6 +267,7 @@
              |ancestor::part[1]
              |ancestor::reference[1]
              |ancestor::article[1]
+             |ancestor::topic[1]
              |$prev-v1
              |$prev-v2)[last()]"/>
 
@@ -355,12 +357,14 @@
              |following::index[$generate.index != 0]
                                [parent::article or parent::book or parent::part][1]
              |following::article[1]
+             |following::topic[1]
              |following::setindex[$generate.index != 0][1]
              |descendant::book[1]
              |descendant::preface[1]
              |descendant::chapter[1]
              |descendant::appendix[1]
              |descendant::article[1]
+             |descendant::topic[1]
              |descendant::bibliography[parent::article or parent::book or parent::part][1]
              |descendant::glossary[parent::article or parent::book or parent::part][1]
              |descendant::index[$generate.index != 0]
@@ -411,6 +415,7 @@
              |preceding::refentry[1]
              |preceding::colophon[1]
              |preceding::article[1]
+             |preceding::topic[1]
              |preceding::bibliography[parent::article or parent::book or parent::part][1]
              |preceding::glossary[parent::article or parent::book or parent::part][1]
              |preceding::index[$generate.index != 0]
@@ -424,6 +429,7 @@
              |ancestor::part[1]
              |ancestor::reference[1]
              |ancestor::article[1]
+             |ancestor::topic[1]
              |$prev-v1
              |$prev-v2)[last()]"/>
 
@@ -458,12 +464,14 @@
              |following::index[$generate.index != 0]
                                [parent::article or parent::book][1]
              |following::article[1]
+             |following::topic[1]
              |following::setindex[$generate.index != 0][1]
              |descendant::book[1]
              |descendant::preface[1]
              |descendant::chapter[1]
              |descendant::appendix[1]
              |descendant::article[1]
+             |descendant::topic[1]
              |descendant::bibliography[parent::article or parent::book][1]
              |descendant::glossary[parent::article or parent::book or parent::part][1]
              |descendant::index[$generate.index != 0]
@@ -941,6 +949,7 @@
        section          if position()>1 && depth < chunk.section.depth
        set
        setindex
+       topic
                                                                             -->
   <!-- ==================================================================== -->
 
@@ -1017,6 +1026,7 @@
     <xsl:when test="local-name($node)='chapter'">1</xsl:when>
     <xsl:when test="local-name($node)='appendix'">1</xsl:when>
     <xsl:when test="local-name($node)='article'">1</xsl:when>
+    <xsl:when test="local-name($node)='topic'">1</xsl:when>
     <xsl:when test="local-name($node)='part'">1</xsl:when>
     <xsl:when test="local-name($node)='reference'">1</xsl:when>
     <xsl:when test="local-name($node)='refentry'">1</xsl:when>
diff --git a/xsl/html/chunktoc.xsl b/xsl/html/chunktoc.xsl
index a50f08aae..48588a105 100644
--- a/xsl/html/chunktoc.xsl
+++ b/xsl/html/chunktoc.xsl
@@ -167,6 +167,10 @@
   <xsl:call-template name="process-chunk"/>
 </xsl:template>
 
+<xsl:template match="topic">
+  <xsl:call-template name="process-chunk"/>
+</xsl:template>
+
 <xsl:template match="article/appendix">
   <xsl:call-template name="process-chunk"/>
 </xsl:template>
diff --git a/xsl/html/component.xsl b/xsl/html/component.xsl
index 318351a47..fb8980ab7 100644
--- a/xsl/html/component.xsl
+++ b/xsl/html/component.xsl
@@ -421,5 +421,51 @@
 
 <!-- ==================================================================== -->
 
+<xsl:template match="topic">
+  <xsl:call-template name="id.warning"/>
+
+  <div>
+    <xsl:call-template name="common.html.attributes">
+      <xsl:with-param name="inherit" select="1"/>
+    </xsl:call-template>
+    <xsl:if test="$generate.id.attributes != 0">
+      <xsl:attribute name="id">
+        <xsl:call-template name="object.id"/>
+      </xsl:attribute>
+    </xsl:if>
+
+    <xsl:call-template name="topic.titlepage"/>
+
+    <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:apply-templates/>
+
+    <xsl:call-template name="process.footnotes"/>
+  </div>
+</xsl:template>
+
+<xsl:template match="topic/title|topic/info/title" mode="titlepage.mode" priority="2">
+  <xsl:call-template name="component.title">
+    <xsl:with-param name="node" select="ancestor::topic[1]"/>
+  </xsl:call-template>
+</xsl:template>
+
+<xsl:template match="topic/subtitle
+                     |topic/info/subtitle"
+              mode="titlepage.mode" priority="2">
+  <xsl:call-template name="component.subtitle">
+    <xsl:with-param name="node" select="ancestor::topic[1]"/>
+  </xsl:call-template>
+</xsl:template>
+
+<xsl:template match="topic/info"></xsl:template>
+<xsl:template match="topic/title"></xsl:template>
+<xsl:template match="topic/titleabbrev"></xsl:template>
+<xsl:template match="topic/subtitle"></xsl:template>
+
 </xsl:stylesheet>
 
diff --git a/xsl/html/titlepage.templates.xml b/xsl/html/titlepage.templates.xml
index cae516026..ce6166f0a 100644
--- a/xsl/html/titlepage.templates.xml
+++ b/xsl/html/titlepage.templates.xml
@@ -334,6 +334,36 @@
   </t:titlepage-before>
 </t:titlepage>
 
+<t:titlepage t:element="topic" t:wrapper="div" class="titlepage">
+  <t:titlepage-content t:side="recto">
+    <title/>
+    <subtitle/>
+    <corpauthor/>
+    <authorgroup/>
+    <author/>
+    <othercredit/>
+    <releaseinfo/>
+    <copyright/>
+    <legalnotice/>
+    <pubdate/>
+    <revision/>
+    <revhistory/>
+    <abstract/>
+  </t:titlepage-content>
+
+  <t:titlepage-content t:side="verso">
+  </t:titlepage-content>
+
+  <t:titlepage-separator>
+  </t:titlepage-separator>
+
+  <t:titlepage-before t:side="recto">
+  </t:titlepage-before>
+
+  <t:titlepage-before t:side="verso">
+  </t:titlepage-before>
+</t:titlepage>
+
 <!-- ==================================================================== -->
 
 <t:titlepage t:element="appendix" t:wrapper="div" class="titlepage">
diff --git a/xsl/html/titlepage.xsl b/xsl/html/titlepage.xsl
index afd703a95..4faca8bd5 100644
--- a/xsl/html/titlepage.xsl
+++ b/xsl/html/titlepage.xsl
@@ -65,6 +65,9 @@
 <xsl:attribute-set name="sidebar.titlepage.recto.style"/>
 <xsl:attribute-set name="sidebar.titlepage.verso.style"/>
 
+<xsl:attribute-set name="topic.titlepage.recto.style"/>
+<xsl:attribute-set name="topic.titlepage.verso.style"/>
+
 <xsl:attribute-set name="section.titlepage.recto.style"/>
 <xsl:attribute-set name="section.titlepage.verso.style"/>
 
diff --git a/xsl/html/xref.xsl b/xsl/html/xref.xsl
index c93c14a42..baaac2608 100644
--- a/xsl/html/xref.xsl
+++ b/xsl/html/xref.xsl
@@ -601,6 +601,19 @@
   <!-- FIXME: What about "in Chapter X"? -->
 </xsl:template>
 
+<xsl:template match="topic" mode="xref-to">
+  <xsl:param name="referrer"/>
+  <xsl:param name="xrefstyle"/>
+  <xsl:param name="verbose" select="1"/>
+
+  <xsl:apply-templates select="." mode="object.xref.markup">
+    <xsl:with-param name="purpose" select="'xref'"/>
+    <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
+    <xsl:with-param name="referrer" select="$referrer"/>
+    <xsl:with-param name="verbose" select="$verbose"/>
+  </xsl:apply-templates>
+</xsl:template>
+
 <xsl:template match="bridgehead" mode="xref-to">
   <xsl:param name="referrer"/>
   <xsl:param name="xrefstyle"/>
@@ -792,6 +805,7 @@
                                        |ancestor::sect3
                                        |ancestor::sect4
                                        |ancestor::sect5
+                                       |ancestor::topic
                                        |ancestor::refsection
                                        |ancestor::refsect1
                                        |ancestor::refsect2
diff --git a/xsl/template/titlepage.xsl b/xsl/template/titlepage.xsl
index fb719b43b..012ff5e65 100644
--- a/xsl/template/titlepage.xsl
+++ b/xsl/template/titlepage.xsl
@@ -773,6 +773,7 @@ names.</para>
       <xsl:when test="ancestor::t:titlepage/@t:element='sect5'"></xsl:when>
       <xsl:when test="ancestor::t:titlepage/@t:element='book'"></xsl:when>
       <xsl:when test="ancestor::t:titlepage/@t:element='set'"></xsl:when>
+      <xsl:when test="ancestor::t:titlepage/@t:element='topic'"></xsl:when>
       <xsl:otherwise>docinfo</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
@@ -880,6 +881,7 @@ names.</para>
       <xsl:when test="ancestor::t:titlepage/@t:element='sect5'"></xsl:when>
       <xsl:when test="ancestor::t:titlepage/@t:element='book'"></xsl:when>
       <xsl:when test="ancestor::t:titlepage/@t:element='set'"></xsl:when>
+      <xsl:when test="ancestor::t:titlepage/@t:element='topic'"></xsl:when>
       <xsl:otherwise>docinfo</xsl:otherwise>
     </xsl:choose>
   </xsl:variable>
diff --git a/xsl/webhelp/xsl/webhelp.xsl b/xsl/webhelp/xsl/webhelp.xsl
index f24f9c053..32cbb5911 100644
--- a/xsl/webhelp/xsl/webhelp.xsl
+++ b/xsl/webhelp/xsl/webhelp.xsl
@@ -755,7 +755,7 @@ border: none; background: none; font-weight: none; color: none; }
 
     <!-- Generates the webhelp table-of-contents (TOC). -->
     <xsl:template
-            match="book|part|reference|preface|chapter|bibliography|appendix|article|glossary|section|simplesect|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index|setindex"
+            match="book|part|reference|preface|chapter|bibliography|appendix|article|topic|glossary|section|simplesect|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv|index|setindex"
             mode="webhelptoc">
         <xsl:param name="currentid"/>
         <xsl:variable name="title">
@@ -794,10 +794,10 @@ border: none; background: none; font-weight: none; color: none; }
                         <xsl:value-of select="$title"/>
                     </a>
                 </span>
-                <xsl:if test="part|reference|preface|chapter|bibliography|appendix|article|glossary|section|simplesect|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv">
+                <xsl:if test="part|reference|preface|chapter|bibliography|appendix|article|topic|glossary|section|simplesect|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv">
                     <ul>
                         <xsl:apply-templates
-                                select="part|reference|preface|chapter|bibliography|appendix|article|glossary|section|simplesect|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv"
+                                select="part|reference|preface|chapter|bibliography|appendix|article|topic|glossary|section|simplesect|sect1|sect2|sect3|sect4|sect5|refentry|colophon|bibliodiv"
                                 mode="webhelptoc">
                             <xsl:with-param name="currentid" select="$currentid"/>
                         </xsl:apply-templates>
-- 
2.40.0