Generate full toc and chapter tocs to look like CSS ones.
authorCameron McCormack <cam@mcc.id.au>
Wed, 09 May 2012 20:46:45 +0200
changeset 11 3ae18dca9e21
parent 10 f933c6bc78a9
child 12 7ab313269006
Generate full toc and chapter tocs to look like CSS ones.
build.py
publish.xsl
--- a/build.py	Wed May 09 19:36:16 2012 +0200
+++ b/build.py	Wed May 09 20:46:45 2012 +0200
@@ -10,12 +10,14 @@
 '''
 '''
 
+# It would be good if the "all" and "tocopy" lists could be extracted from
+# publish.xml instead of being hard coded here.
 all = """
   index
   eltindex
   attindex
   propidx
-  expanded-toc
+  toc
   intro
   concepts
   render
--- a/publish.xsl	Wed May 09 19:36:16 2012 +0200
+++ b/publish.xsl	Wed May 09 20:46:45 2012 +0200
@@ -257,40 +257,37 @@
     <h1>
       <xsl:copy-of select='@*[namespace-uri() = ""]'/>
       <xsl:if test='$chapter-number'>
-        <xsl:value-of select='if ($chapter-type = "appendix") then concat("Appendix ", $chapter-number, ": ") else concat($chapter-number, " ")'/>
+        <xsl:value-of select='if ($chapter-type = "appendix") then concat("Appendix ", $chapter-number, ": ") else if ($chapter-type = "chapter") then concat("Chapter ", $chapter-number, ": ") else ""'/>
       </xsl:if>
       <xsl:apply-templates select='node()'/>
     </h1>
     <xsl:if test='$chapter-type != "index" and $sections/*/*'>
-      <h2 id='toc'>Contents</h2>
-      <ul class='toc'>
-        <xsl:apply-templates select='$sections/*/x:section'/>
+      <h2 id='toc' class='contents'>Contents</h2>
+      <xsl:variable name='class' select='if ($chapter-type = "chapter") then "toc" else "toc appendix-toc"'/>
+      <ul class='{$class}'>
+        <li>
+          <ul class='{$class}'>
+            <xsl:apply-templates select='$sections/*/x:section'>
+              <xsl:with-param name='no-num' select='$chapter-type != "chapter"' tunnel='yes'/>
+            </xsl:apply-templates>
+          </ul>
+        </li>
       </ul>
     </xsl:if>
   </xsl:template>
 
   <xsl:template match='edit:minitoc'>
-    <xsl:if test='$conf/x:page'>
-      <ul class='toc'>
-        <xsl:for-each select='$conf/x:page'>
-          <li class="no-num"><a href='{@name}.html'><xsl:value-of select='document(concat(@name, ".html"), .)/html/body/h1'/></a></li>
-        </xsl:for-each>
-      </ul>
-    </xsl:if>
-    <xsl:if test='$conf/x:chapter'>
-      <ul class='toc'>
-        <xsl:for-each select='$conf/x:chapter'>
-          <li><a href='{@name}.html'><span class="secno"><xsl:value-of select='position()'/>.</span><xsl:text> </xsl:text><xsl:value-of select='document(concat(@name, ".html"), .)/html/body/h1'/></a></li>
-        </xsl:for-each>
-      </ul>
-    </xsl:if>
-    <xsl:if test='$conf/x:appendix'>
-      <ul class='toc'>
-        <xsl:for-each select='$conf/x:appendix'>
-          <li class="no-num"><a href='{@name}.html'>Appendix <xsl:number value='position()' format='A'/>: <xsl:value-of select='document(concat(@name, ".html"), .)/html/body/h1'/></a></li>
-        </xsl:for-each>
-      </ul>
-    </xsl:if>
+    <ul class='toc'>
+      <xsl:for-each select='$conf/x:page'>
+        <li class="no-num"><a href='{@name}.html'><xsl:value-of select='document(concat(@name, ".html"), .)/html/body/h1'/></a></li>
+      </xsl:for-each>
+      <xsl:for-each select='$conf/x:chapter'>
+        <li><a href='{@name}.html'><span class="secno"><xsl:value-of select='position()'/>.</span><xsl:text> </xsl:text><xsl:value-of select='document(concat(@name, ".html"), .)/html/body/h1'/></a></li>
+      </xsl:for-each>
+      <xsl:for-each select='$conf/x:appendix'>
+        <li class="no-num"><a href='{@name}.html'>Appendix <xsl:number value='position()' format='A'/>: <xsl:value-of select='document(concat(@name, ".html"), .)/html/body/h1'/></a></li>
+      </xsl:for-each>
+    </ul>
   </xsl:template>
 
   <xsl:template match='edit:fulltoc'>
@@ -302,50 +299,41 @@
         </ul>
       </xsl:when>
       <xsl:otherwise>
-        <xsl:if test='$conf/x:page'>
-          <ul class='toc'>
-            <xsl:for-each select='$conf/x:page'>
-              <li class='tocline1'><a href='{@name}.html'><xsl:value-of select='document(concat(@name, ".html"), .)/html/body/h1'/></a></li>
-            </xsl:for-each>
-          </ul>
-        </xsl:if>
-        <xsl:if test='$conf/x:chapter'>
-          <ol class='toc'>
-            <xsl:for-each select='$conf/x:chapter'>
-              <xsl:variable name='doc' select='document(concat(@name, ".html"), .)'/>
-              <xsl:variable name='s' select='x:gather-sections($doc//h1[1], position())'/>
-              <li><div class='tocline1'><a href='{@name}.html'><xsl:value-of select='position()'/><xsl:text> </xsl:text><xsl:value-of select='$doc/html/body/h1'/></a></div>
-                <xsl:if test='$s/*/x:section'>
-                  <ul class='toc'>
-                    <xsl:apply-templates select='$s/*/x:section'>
-                      <xsl:with-param name='toc-filename' select='concat(@name, ".html")' tunnel='yes'/>
-                    </xsl:apply-templates>
-                  </ul>
-                </xsl:if>
-              </li>
-            </xsl:for-each>
-          </ol>
-        </xsl:if>
-        <xsl:if test='$conf/x:appendix'>
-          <ol class='toc'>
-            <xsl:for-each select='$conf/x:appendix'>
-              <xsl:variable name='doc' select='document(concat(@name, ".html"), .)'/>
-              <xsl:variable name='num'>
-                <xsl:number value='position()' format='A'/>
-              </xsl:variable>
-              <xsl:variable name='s' select='x:gather-sections($doc//h1[1], $num)'/>
-              <li><div class='tocline1'><a href='{@name}.html'>Appendix <xsl:value-of select='$num'/>: <xsl:value-of select='$doc/html/body/h1'/></a></div>
-                <xsl:if test='$s/*/x:section'>
-                  <ul class='toc'>
-                    <xsl:apply-templates select='$s/*/x:section'>
-                      <xsl:with-param name='toc-filename' select='concat(@name, ".html")' tunnel='yes'/>
-                    </xsl:apply-templates>
-                  </ul>
-                </xsl:if>
-              </li>
-            </xsl:for-each>
-          </ol>
-        </xsl:if>
+        <ul class='toc'>
+          <xsl:for-each select='$conf/x:page[not(@toc)]'>
+            <li><a href='{@name}.html'><xsl:value-of select='document(concat(@name, ".html"), .)/html/body/h1'/></a></li>
+          </xsl:for-each>
+          <xsl:for-each select='$conf/x:chapter'>
+            <xsl:variable name='doc' select='document(concat(@name, ".html"), .)'/>
+            <xsl:variable name='s' select='x:gather-sections($doc//h1[1], position())'/>
+            <li><a href='{@name}.html'><span class='secno'><xsl:value-of select='position()'/>.</span><xsl:text> </xsl:text><xsl:value-of select='$doc/html/body/h1'/></a>
+              <xsl:if test='$s/*/x:section'>
+                <ul class='toc'>
+                  <xsl:apply-templates select='$s/*/x:section'>
+                    <xsl:with-param name='toc-filename' select='concat(@name, ".html")' tunnel='yes'/>
+                  </xsl:apply-templates>
+                </ul>
+              </xsl:if>
+            </li>
+          </xsl:for-each>
+          <xsl:for-each select='$conf/x:appendix'>
+            <xsl:variable name='doc' select='document(concat(@name, ".html"), .)'/>
+            <xsl:variable name='num'>
+              <xsl:number value='position()' format='A'/>
+            </xsl:variable>
+            <xsl:variable name='s' select='x:gather-sections($doc//h1[1], $num)'/>
+            <li class='no-num'><a href='{@name}.html'>Appendix <xsl:value-of select='$num'/>: <xsl:value-of select='$doc/html/body/h1'/></a>
+              <xsl:if test='$s/*/x:section'>
+                <ul class='toc'>
+                  <xsl:apply-templates select='$s/*/x:section'>
+                    <xsl:with-param name='toc-filename' select='concat(@name, ".html")' tunnel='yes'/>
+                    <xsl:with-param name='no-num' select='true()' tunnel='yes'/>
+                  </xsl:apply-templates>
+                </ul>
+              </xsl:if>
+            </li>
+          </xsl:for-each>
+        </ul>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:template>
@@ -357,18 +345,21 @@
     <xsl:variable name='section-number' select='x:section-number($sections, x:section-id(.))'/>
     <xsl:element namespace='http://www.w3.org/1999/xhtml' name='{local-name()}'>
       <xsl:copy-of select='@*[namespace-uri() = ""]'/>
-      <xsl:value-of select='if (not($chapter-type = "index" and not($single-chapter)) and $section-number) then concat($section-number, " ") else ""'/>
+      <xsl:value-of select='if (not($chapter-type = "index" and not($single-chapter)) and $chapter-type != "appendix" and $section-number) then concat($section-number, ". ") else ""'/>
       <xsl:apply-templates select='node()'/>
     </xsl:element>
   </xsl:template>
 
   <xsl:template match='x:section'>
     <xsl:param name='toc-filename' tunnel='yes'/>
+    <xsl:param name='no-num' tunnel='yes'/>
     <xsl:text>&#10;</xsl:text>
     <li>
       <a href='{$toc-filename}#{@xml:id}'>
-        <xsl:value-of select='@number'/>
-        <xsl:text> </xsl:text>
+        <xsl:if test='not($no-num)'>
+          <span class='secno'><xsl:value-of select='@number'/>.</span>
+          <xsl:text> </xsl:text>
+        </xsl:if>
         <xsl:apply-templates select='x:title/node()'/>
       </a>
       <xsl:if test='x:section'>