]> granicus.if.org Git - docbook-dsssl/commitdiff
Add two new qanda.defaultlabel values so that numbered sections
authorBob Stayton <bobs@sagehill.net>
Tue, 17 Mar 2009 07:24:29 +0000 (07:24 +0000)
committerBob Stayton <bobs@sagehill.net>
Tue, 17 Mar 2009 07:24:29 +0000 (07:24 +0000)
and numbered questions can be distinguished.  Satisfies
Feature Request #1539045.

xsl/common/labels.xsl
xsl/fo/qandaset.xsl
xsl/html/qandaset.xsl
xsl/params/qanda.defaultlabel.xml

index 4cfeae94ec182dc36e31de3a25c6464561ee627a..3d9ce5ca5e1b85c276aff0f3e9bd4ac8a7807d0b 100644 (file)
@@ -570,9 +570,14 @@ element label.</para>
     <xsl:if test="$qanda.inherit.numeration != 0">
       <xsl:choose>
         <xsl:when test="ancestor::qandadiv">
-          <xsl:apply-templates select="ancestor::qandadiv[1]" mode="label.markup"/>
-          <xsl:apply-templates select="ancestor::qandadiv[1]"
-                               mode="intralabel.punctuation"/>
+          <xsl:variable name="div.label">
+            <xsl:apply-templates select="ancestor::qandadiv[1]" mode="label.markup"/>
+          </xsl:variable>
+          <xsl:if test="string-length($div.label) != 0">
+            <xsl:copy-of select="$div.label"/>
+            <xsl:apply-templates select="ancestor::qandadiv[1]"
+                                 mode="intralabel.punctuation"/>
+          </xsl:if>
         </xsl:when>
         <xsl:when test="$lparent.prefix != ''">
           <xsl:apply-templates select="$lparent" mode="label.markup"/>
@@ -603,19 +608,35 @@ element label.</para>
       <xsl:apply-templates select="$label"/>
     </xsl:when>
 
-    <xsl:when test="$deflabel = 'qanda' and local-name(.) = 'question'">
+    <xsl:when test="$deflabel = 'qanda' and self::question">
       <xsl:call-template name="gentext">
         <xsl:with-param name="key" select="'Question'"/>
       </xsl:call-template>
     </xsl:when>
 
-    <xsl:when test="$deflabel = 'qanda' and local-name(.) = 'answer'">
+    <xsl:when test="$deflabel = 'qanda' and self::answer">
       <xsl:call-template name="gentext">
         <xsl:with-param name="key" select="'Answer'"/>
       </xsl:call-template>
     </xsl:when>
 
-    <xsl:when test="$deflabel = 'number' and local-name(.) = 'question'">
+    <xsl:when test="($deflabel = 'qnumber' or
+                     $deflabel = 'qnumberanda') and self::question">
+      <xsl:call-template name="gentext">
+        <xsl:with-param name="key" select="'Question'"/>
+      </xsl:call-template>
+      <xsl:text>&#xA0;</xsl:text>
+      <xsl:value-of select="$prefix"/>
+      <xsl:number level="multiple" count="qandaentry" format="1"/>
+    </xsl:when>
+
+    <xsl:when test="$deflabel = 'qnumberanda' and self::answer">
+      <xsl:call-template name="gentext">
+        <xsl:with-param name="key" select="'Answer'"/>
+      </xsl:call-template>
+    </xsl:when>
+
+    <xsl:when test="$deflabel = 'number' and self::question">
       <xsl:value-of select="$prefix"/>
       <xsl:number level="multiple" count="qandaentry" format="1"/>
     </xsl:when>
@@ -722,11 +743,11 @@ element label.</para>
             <xsl:apply-templates select="$pchap" mode="intralabel.punctuation"/>
           </xsl:if>
           <xsl:number format="1" count="equation[title or info/title]" 
-                     from="chapter|appendix" level="any"/>
+                      from="chapter|appendix" level="any"/>
         </xsl:when>
         <xsl:otherwise>
           <xsl:number format="1" count="equation[title or info/title]" 
-                     from="book|article" level="any"/>
+                      from="book|article" level="any"/>
         </xsl:otherwise>
       </xsl:choose>
     </xsl:otherwise>
@@ -838,9 +859,9 @@ Custom stylesheets may override it to get more selective behavior.</para>
         <xsl:when test="$format='upperroman' or $format='I'">
           <xsl:value-of select="'I'"/>
         </xsl:when>      
-       <xsl:when test="$format='arabicindic' or $format='&#x661;'">
-         <xsl:value-of select="'&#x661;'"/>
-       </xsl:when>
+        <xsl:when test="$format='arabicindic' or $format='&#x661;'">
+          <xsl:value-of select="'&#x661;'"/>
+        </xsl:when>
         <xsl:otherwise>
           <xsl:message>
             <xsl:text>Unexpected </xsl:text><xsl:value-of select="local-name(.)"/><xsl:text>.autolabel value: </xsl:text>
index a29692f671202df036ca1c0aa9eceb5da711ee04..f6c4d3948445251d12de1c7a56fbff52ae9ccf01 100644 (file)
     <xsl:call-template name="object.id"/>
   </xsl:variable>
 
-  <xsl:variable name="label-width">
-    <xsl:call-template name="pi.dbfo_label-width"/>
-  </xsl:variable>
-
   <xsl:variable name="label-length">
-    <xsl:choose>
-      <xsl:when test="$label-width != ''">
-        <xsl:value-of select="$label-width"/>
-      </xsl:when>
-      <xsl:when test="descendant::label">
-        <xsl:call-template name="longest.term">
-          <xsl:with-param name="terms" select="descendant::label"/>
-          <xsl:with-param name="maxlength" select="20"/>
-        </xsl:call-template>
-        <xsl:text>em * 0.50</xsl:text>
-      </xsl:when>
-      <xsl:otherwise>2.5em</xsl:otherwise>
-    </xsl:choose>
+    <xsl:call-template name="qandaset.label.length"/>
   </xsl:variable>
   
   <xsl:variable name="toc">
   
 </xsl:template>
 
+<xsl:template name="qandaset.label.length">
+  <xsl:param name="deflabel">
+    <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
+  </xsl:param>
+
+  <xsl:variable name="label-width">
+    <xsl:call-template name="pi.dbfo_label-width"/>
+  </xsl:variable>
+
+  <xsl:choose>
+    <xsl:when test="$label-width != ''">
+      <xsl:value-of select="$label-width"/>
+    </xsl:when>
+    <xsl:when test="descendant::label">
+      <xsl:call-template name="longest.term">
+        <xsl:with-param name="terms" select="descendant::label"/>
+        <xsl:with-param name="maxlength" select="20"/>
+      </xsl:call-template>
+      <xsl:text>em * 0.50</xsl:text>
+    </xsl:when>
+    <xsl:when test="contains($deflabel, 'qnumber') and
+                    $qandadiv.autolabel != 0 and
+                    $qanda.inherit.numeration != 0">
+      <xsl:text>5em</xsl:text>
+    </xsl:when>
+    <xsl:when test="$deflabel ='qnumber' and
+                    $qandadiv.autolabel != 0 and
+                    $qanda.inherit.numeration != 0">
+      <xsl:text>4em</xsl:text>
+    </xsl:when>
+    <xsl:when test="$deflabel = 'number'">
+      <xsl:text>3em</xsl:text>
+    </xsl:when>
+    <xsl:otherwise>2.5em</xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
 <xsl:template match="qandaset/blockinfo/title|qandset/info/title|qandaset/title">
   <xsl:variable name="enclsect" select="(ancestor::section
                                         | ancestor::simplesect
 <xsl:template match="qandadiv">
   <xsl:variable name="id"><xsl:call-template name="object.id"/></xsl:variable>
 
-  <xsl:variable name="label-width">
-    <xsl:call-template name="pi.dbfo_label-width"/>
-  </xsl:variable>
 
   <xsl:variable name="label-length">
-    <xsl:choose>
-      <xsl:when test="$label-width != ''">
-        <xsl:value-of select="$label-width"/>
-      </xsl:when>
-      <xsl:when test="descendant::label">
-        <xsl:call-template name="longest.term">
-          <xsl:with-param name="terms" select="descendant::label"/>
-          <xsl:with-param name="maxlength" select="20"/>
-        </xsl:call-template>
-        <xsl:text>*0.6em</xsl:text>
-      </xsl:when>
-      <xsl:otherwise>2.5em</xsl:otherwise>
-    </xsl:choose>
+    <xsl:call-template name="qandaset.label.length"/>
   </xsl:variable>
-
+  
   <fo:block id="{$id}">
     <xsl:apply-templates select="(blockinfo/title|info/title|title)[1]"/>
     <xsl:apply-templates select="*[local-name(.) != 'title'
   </xsl:variable>
 
   <xsl:variable name="deflabel">
-    <xsl:choose>
-      <xsl:when test="ancestor-or-self::*[@defaultlabel]">
-        <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
-                              /@defaultlabel"/>
-      </xsl:when>
-      <xsl:otherwise>
-        <xsl:value-of select="$qanda.defaultlabel"/>
-      </xsl:otherwise>
-    </xsl:choose>
+    <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
   </xsl:variable>
 
 
-      <xsl:variable name="label.content">
-        <xsl:apply-templates select="." mode="label.markup"/>
-        <xsl:if test="$deflabel = 'number' and not(label)">
-          <xsl:apply-templates select="." mode="intralabel.punctuation"/>
-        </xsl:if>
-      </xsl:variable>
+  <xsl:variable name="label.content">
+    <xsl:apply-templates select="." mode="label.markup"/>
+    <xsl:if test="contains($deflabel, 'number') and not(label)">
+      <xsl:apply-templates select="." mode="intralabel.punctuation"/>
+    </xsl:if>
+  </xsl:variable>
 
   <fo:list-item id="{$entry.id}" xsl:use-attribute-sets="list.item.spacing">
     <fo:list-item-label id="{$id}" end-indent="label-end()">
   </xsl:variable>
 
   <xsl:variable name="deflabel">
-    <xsl:choose>
-      <xsl:when test="ancestor-or-self::*[@defaultlabel]">
-        <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
-                              /@defaultlabel"/>
-      </xsl:when>
-      <xsl:otherwise>
-        <xsl:value-of select="$qanda.defaultlabel"/>
-      </xsl:otherwise>
-    </xsl:choose>
+    <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
   </xsl:variable>
 
       <xsl:variable name="answer.label">
   </fo:list-item>
 </xsl:template>
 
+<xsl:template match="*" mode="qanda.defaultlabel">
+  <xsl:choose>
+    <xsl:when test="ancestor-or-self::*[@defaultlabel]">
+      <xsl:value-of select="(ancestor-or-self::*[@defaultlabel])[last()]
+                            /@defaultlabel"/>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="$qanda.defaultlabel"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
 <xsl:template match="label">
   <xsl:apply-templates/>
 </xsl:template>
index 30dbdb1a428962b3b14c1ce5684f07b1667b7083..48702b9b750c43565bf83c318ae183e5d6dc0251 100644 (file)
     <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
   </xsl:variable>
   <xsl:apply-templates select="." mode="label.markup"/>
-  <xsl:if test="$deflabel = 'number' and not(label)">
+  <xsl:if test="contains($deflabel, 'number') and not(label)">
     <xsl:apply-templates select="." mode="intralabel.punctuation"/>
   </xsl:if>
 </xsl:template>
     </xsl:call-template>
   </xsl:variable>
 
-  <xsl:apply-templates select="parent::qandadiv" mode="label.markup"/>
-  <xsl:value-of select="$autotoc.label.separator"/>
+  <xsl:variable name="div.label">
+    <xsl:apply-templates select="parent::qandadiv" mode="label.markup"/>
+  </xsl:variable>
+  <xsl:if test="string-length($div.label) != 0">
+    <xsl:copy-of select="$div.label"/>
+    <xsl:value-of select="$autotoc.label.separator"/>
+  </xsl:if>
   <xsl:text> </xsl:text>
   <a>
     <xsl:attribute name="href">
 
   <dt>
     <xsl:apply-templates select="." mode="label.markup"/>
-    <xsl:if test="$deflabel = 'number' and not(label)">
+    <xsl:if test="contains($deflabel,'number') and not(label)">
       <xsl:apply-templates select="." mode="intralabel.punctuation"/>
     </xsl:if>
     <xsl:text> </xsl:text>
 
 <xsl:template name="process.qandaset">
 
+  <xsl:variable name="deflabel">
+    <xsl:apply-templates select="." mode="qanda.defaultlabel"/>
+  </xsl:variable>
+
   <xsl:variable name="label-width">
     <xsl:call-template name="pi.dbhtml_label-width"/>
   </xsl:variable>
     <xsl:call-template name="pi.dbhtml_cellspacing"/>
   </xsl:variable>
 
-  <table border="0" summary="Q and A Set">
+  <table border="0" width="100%" summary="Q and A Set">
     <xsl:if test="$table-summary != ''">
       <xsl:attribute name="summary">
         <xsl:value-of select="$table-summary"/>
           <xsl:when test="$label-width != ''">
             <xsl:value-of select="$label-width"/>
           </xsl:when>
-          <xsl:otherwise>1%</xsl:otherwise>
+          <xsl:otherwise>
+            <xsl:text>1%</xsl:text>
+          </xsl:otherwise>
         </xsl:choose>
       </xsl:attribute>
     </col>
+    <col/>
     <tbody>
       <xsl:apply-templates select="qandaentry|qandadiv"/>
     </tbody>
index 0b3f194115c071e80294a5ee47a4a132620bc88f..d75114cd663ab944c73f18260ae6dcbb08f6909f 100644 (file)
 <refsection><info><title>Description</title></info>
 
 <para>If no <literal>defaultlabel</literal> attribute is specified on
-a <tag>qandaset</tag>, this value is used. It must be one of the legal
-values for the defaultlabel attribute, one from none, number or
-qanda. The default value is 'number'.
+a <tag>qandaset</tag>, this value is used. It is generally one of the legal
+values for the defaultlabel attribute (<literal>none</literal>, 
+<literal>number</literal> or
+<literal>qanda</literal>), or one of the additional stylesheet-specific values
+(<literal>qnumber</literal> or <literal>qnumberanda</literal>).
+The default value is 'number'.
 </para>
-<para>Meaning</para>
-<para>qanda -   <tag>question</tag>s are labeled “Q:” and <tag>answer</tag>s are labeled “A:”. </para>
-<para>number -    The entries are enumerated. </para>
-<para>none -    No distinguishing label precedes Questions or Answers. 
+<para>The values are rendered as follows:</para>
+<variablelist>
+<varlistentry><term><literal>qanda</literal></term>
+<listitem>
+<para><tag>question</tag>s are labeled "Q:" and
+<tag>answer</tag>s are labeled "A:". </para>
+</listitem>
+</varlistentry>
 
+<variablelist>
+<varlistentry><term><literal>number</literal></term>
+<listitem>
+<para>The questions are enumerated and the answers
+are not labeled. </para>
+</listitem>
+</varlistentry>
+<variablelist>
+<varlistentry><term><literal>qnumber</literal></term>
+<listitem>
+<para>The questions are labeled "Q:" followed by a number, and answers are not 
+labeled. 
+When sections are numbered, adding a label
+to the number distinguishes the question numbers
+from the section numbers.
+This value is not allowed in the
+<tag class="attribute">defaultlabel</tag> attribute
+of a <tag>qandaset</tag> element.</para>
+</listitem>
+</varlistentry>
+<variablelist>
+<varlistentry><term><literal>qnumberanda</literal></term>
+<listitem>
+<para>The questions are labeled "Q:" followed by a number, and
+the answers are labeled "A:". 
+When sections are numbered, adding a label
+to the number distinguishes the question numbers
+from the section numbers.
+This value is not allowed in the
+<tag class="attribute">defaultlabel</tag> attribute
+of a <tag>qandaset</tag> element.</para>
+</listitem>
+</varlistentry>
+<variablelist>
+<varlistentry><term><literal>none</literal></term>
+<listitem>
+<para>No distinguishing label precedes Questions or Answers. 
 </para>
-
-
-
-
+</listitem>
+</varlistentry>
+</variablelist>
 
 </refsection>
 </refentry>