From 7a0e400ce39f914cc9149901eb76056e655900ee Mon Sep 17 00:00:00 2001
From: "Dr. Martin Goik" <goik@hdm-stuttgart.de>
Date: Sun, 4 Nov 2018 10:33:34 +0100
Subject: [PATCH] Numbering exercises per lecture

---
 .../CustomLayer/webhelp/hdmextensions.xsl     |  9 +++++--
 ws/Docbook/Preprocess/Xsl/docbook2docbook.xsl | 24 +++++++++++++++----
 2 files changed, 27 insertions(+), 6 deletions(-)

diff --git a/ws/Docbook/CustomLayer/webhelp/hdmextensions.xsl b/ws/Docbook/CustomLayer/webhelp/hdmextensions.xsl
index cacd6a82a..bd995d733 100644
--- a/ws/Docbook/CustomLayer/webhelp/hdmextensions.xsl
+++ b/ws/Docbook/CustomLayer/webhelp/hdmextensions.xsl
@@ -76,8 +76,13 @@
       <xsl:call-template name="id.attribute">
         <xsl:with-param name="conditional" select="0"/>
       </xsl:call-template>
+      <xsl:variable name="parentId" select="ancestor::d:part/@xml:id"/>
+      <p>
+        <img title="Exercise" alt="exercise"  style="vertical-align: middle;" width="40em"  src="common/images/yoga-exercise.svg"/>
+        <xsl:text> No. </xsl:text>
+        <xsl:value-of select="count(preceding::d:qandaset[ancestor::d:part/@xml:id = $parentId]) + 1"/>
+      </p>
       
-      <img title="Exercise" alt="exercise"  style="vertical-align: middle;" width="40em"  src="common/images/yoga-exercise.svg"/>
       <xsl:apply-templates select="$title"/>
       <xsl:if test="not($title)">
         <!-- andhor is output on title if there is one -->
@@ -85,7 +90,7 @@
           <xsl:with-param name="conditional" select="0"/>
         </xsl:call-template>
       </xsl:if>
-      <xsl:if test="((contains($toc.params, 'toc') and $toc != '0') or $toc = '1')                   and not(ancestor::d:answer and not($qanda.nested.in.toc=0))">
+      <xsl:if test="((contains($toc.params, 'toc') and $toc != '0') or $toc = '1') and not(ancestor::d:answer and not($qanda.nested.in.toc=0))">
         <xsl:call-template name="process.qanda.toc"/>
       </xsl:if>
       <xsl:apply-templates select="$preamble"/>
diff --git a/ws/Docbook/Preprocess/Xsl/docbook2docbook.xsl b/ws/Docbook/Preprocess/Xsl/docbook2docbook.xsl
index 20d771c55..2b0bd9022 100644
--- a/ws/Docbook/Preprocess/Xsl/docbook2docbook.xsl
+++ b/ws/Docbook/Preprocess/Xsl/docbook2docbook.xsl
@@ -43,15 +43,20 @@
             <caption>
               <xsl:text>Exercises in </xsl:text>
               <emphasis>
-                <xsl:value-of select="db:info/db:title" />
+                <xsl:value-of select="ancestor-or-self::db:part/db:title" />
               </emphasis>
             </caption>
             <col width="25%" />
+            <col width="2%" />
             <col width="45%" />
-            <col width="30%" />
+            <col width="28%" />
             <tr>
-              <th>Chapter</th>
-              <th>Exercise title / page</th>
+              <th rowspan="2">Chapter</th>
+              <th colspan="3">Exercise</th>
+            </tr>
+            <tr>
+              <th>No.</th>
+              <th>Title</th>
               <th>Status of completion</th>
             </tr>
             
@@ -63,6 +68,9 @@
                       <xref linkend="{current-grouping-key()}"/>
                     </td>
                   </xsl:if>
+                  <td style="text-align: right;">
+                    <xsl:apply-templates select="." mode="qandaNumber"/>
+                  </td>
                   <td>
                     <xsl:apply-templates select="." mode="selectOwnOrInheritedTitle"/>
                   </td>
@@ -72,12 +80,20 @@
               
             </xsl:for-each-group>                    
           </table>
+          <!-- Not really useful:
+            
           <xsl:apply-templates select="db:chapter[descendant::db:qandaset]" mode="genQuandaset"/>
+          -->
         </appendix>
       </xsl:if>
     </xsl:copy>        
   </xsl:template>
   
+  <xsl:template match="db:qandaset" mode="qandaNumber">
+    <xsl:variable name="parentId" select="ancestor::db:part/@xml:id"/>    
+    <xsl:value-of select="count(preceding::db:qandaset[ancestor::db:part/@xml:id = $parentId]) + 1"/>
+  </xsl:template>
+  
   
   <xsl:template match="db:chapter" mode="genQuandaset">
     <section xml:id="{@xml:id}_qanda">
-- 
GitLab