]> granicus.if.org Git - docbook-dsssl/commitdiff
Add support for some format properties on tables using
authorBob Stayton <bobs@sagehill.net>
Wed, 1 Apr 2009 08:47:55 +0000 (08:47 +0000)
committerBob Stayton <bobs@sagehill.net>
Wed, 1 Apr 2009 08:47:55 +0000 (08:47 +0000)
HTML table markup.  These include:
  - frame attribute on table (or uses $default.table.frame parameter).
  - rules attribute on table (or uses $default.table.rules parameter).
  - align attribute on td and th
  - valign attribute on td and th
  - colspan on td and th
  - rowspan on td and th
  - bgcolor on td and th

xsl/common/table.xsl
xsl/fo/htmltbl.xsl
xsl/fo/param.ent
xsl/fo/param.xweb
xsl/fo/table.xsl

index 85bf43fa18dc1ce03dcd19e0a6327839cef83d10..7ce298cdd7523168f5520795d30144c80a601684 100644 (file)
@@ -258,7 +258,7 @@ or 0 (the empty string)</para>
 
   <xsl:variable name="table" select="($tgroup/ancestor::table
                                      |$tgroup/ancestor::informaltable
-                                    |$entry/ancestor::entrytbl)[last()]"/>
+                                     |$entry/ancestor::entrytbl)[last()]"/>
 
   <xsl:variable name="entry.value">
     <xsl:call-template name="get-attribute">
@@ -411,7 +411,7 @@ or 0 (the empty string)</para>
   <xsl:param name="attribute" select="'colname'"/>
   <xsl:param name="colspec.ancestor" 
              select="(ancestor::tgroup|ancestor::entrytbl)
-                    [position() = last()]"/>
+                     [position() = last()]"/>
   <xsl:param name="colspecs" select="$colspec.ancestor/colspec"/>
   <xsl:param name="count" select="1"/>
 
index 14f0105ba4c054141c4a14cd279113ed7d9749ba..cfaa28fce37483f2a50505f48313925e1e391141 100644 (file)
 
 <!-- ==================================================================== -->
 
-<xsl:attribute-set name="th.style">
-  <xsl:attribute name="font-weight">bold</xsl:attribute>
-</xsl:attribute-set>
-
 <!-- Outputs an fo:table only, not the caption -->
 <xsl:template match="table|informaltable" mode="htmlTable">
 
@@ -43,6 +39,7 @@
         <xsl:attribute name="table-layout">fixed</xsl:attribute>
       </xsl:when>
     </xsl:choose>
+
     <xsl:attribute name="width">
       <xsl:choose>
         <xsl:when test="@width">
         <xsl:otherwise>100%</xsl:otherwise>
       </xsl:choose>
     </xsl:attribute>
+
+    <xsl:call-template name="table.frame">
+      <xsl:with-param name="frame">
+        <xsl:choose>
+          <xsl:when test="@frame = 'box'">all</xsl:when>
+          <xsl:when test="@frame = 'border'">all</xsl:when>
+          <xsl:when test="@frame = 'below'">bottom</xsl:when>
+          <xsl:when test="@frame = 'above'">top</xsl:when>
+          <xsl:when test="@frame = 'hsides'">topbot</xsl:when>
+          <xsl:when test="@frame = 'vsides'">sides</xsl:when>
+          <xsl:when test="@frame = 'lhs'">lhs</xsl:when>
+          <xsl:when test="@frame = 'rhs'">rhs</xsl:when>
+          <xsl:when test="@frame = 'void'">none</xsl:when>
+          <xsl:when test="@border != '' and @border != 0">all</xsl:when>
+          <xsl:when test="@border != '' and @border = 0">none</xsl:when>
+          <xsl:when test="@frame != ''">
+            <xsl:value-of select="@frame"/>
+          </xsl:when>
+          <xsl:when test="$default.table.frame != ''">
+            <xsl:value-of select="$default.table.frame"/>
+          </xsl:when>
+          <xsl:otherwise>all</xsl:otherwise>
+        </xsl:choose>
+      </xsl:with-param>
+    </xsl:call-template>
+
     <xsl:call-template name="make-html-table-columns">
       <xsl:with-param name="count" select="$numcols"/>
     </xsl:call-template>
+
     <xsl:apply-templates select="thead" mode="htmlTable"/>
     <xsl:apply-templates select="tfoot" mode="htmlTable"/>
     <xsl:choose>
 
 </xsl:template>
 
+<!-- This template writes rowsep or colsep equivalant for html tables -->
+<xsl:template name="html.table.cell.rules">
+  <xsl:variable name="border" 
+                select="(ancestor::table |
+                         ancestor::informaltable)[last()]/@border"/>
+  <xsl:variable name="table.rules"
+                select="(ancestor::table |
+                         ancestor::informaltable)[last()]/@rules"/>
+
+  <xsl:variable name="rules">
+    <xsl:choose>
+      <xsl:when test="$table.rules != ''">
+        <xsl:value-of select="$table.rules"/>
+      </xsl:when>
+      <xsl:when test="$default.table.rules != ''">
+        <xsl:value-of select="$default.table.rules"/>
+      </xsl:when>
+    </xsl:choose>
+  </xsl:variable>
+
+  <xsl:choose>
+    <xsl:when test="$border != '' and $border != 0">
+      <xsl:attribute name="border">
+        <xsl:value-of select="$table.cell.border.thickness"/>
+        <xsl:text> </xsl:text>
+        <xsl:value-of select="$table.cell.border.style"/>
+        <xsl:text> </xsl:text>
+        <xsl:value-of select="$table.cell.border.color"/>
+      </xsl:attribute>
+    </xsl:when>
+    <xsl:when test="$rules = 'none'">
+      <xsl:attribute name="border-start-style">none</xsl:attribute>
+      <xsl:attribute name="border-end-style">none</xsl:attribute>
+      <xsl:attribute name="border-top-style">none</xsl:attribute>
+      <xsl:attribute name="border-bottom-style">none</xsl:attribute>
+    </xsl:when>
+
+    <xsl:when test="$rules = 'cols' and following-sibling::*">
+      <!-- If not the last column, add border after -->
+      <xsl:attribute name="border-start-style">none</xsl:attribute>
+      <xsl:attribute name="border-top-style">none</xsl:attribute>
+      <xsl:attribute name="border-bottom-style">none</xsl:attribute>
+      <xsl:attribute name="border-end-style">
+        <xsl:value-of select="$table.frame.border.style"/>
+      </xsl:attribute>
+      <xsl:attribute name="border-end-width">
+        <xsl:value-of select="$table.frame.border.thickness"/>
+      </xsl:attribute>
+      <xsl:attribute name="border-end-color">
+        <xsl:value-of select="$table.frame.border.color"/>
+      </xsl:attribute>
+    </xsl:when>
+    <!-- If not the last row, add border below -->
+    <xsl:when test="$rules = 'rows'">
+      <xsl:variable name="rowborder">
+        <xsl:choose>
+          <!-- If in thead and tbody has rows, add border -->
+          <xsl:when test="parent::tr/parent::thead/
+                          following-sibling::tbody/tr">1</xsl:when>
+          <!-- If in tbody and tfoot has rows, add border -->
+          <xsl:when test="parent::tr/parent::tbody/
+                          following-sibling::tfoot/tr">1</xsl:when>
+          <xsl:when test="parent::tr/parent::tbody/
+                          preceding-sibling::tfoot/tr">1</xsl:when>
+          <!-- If following rows, but not rowspan reaches last row -->
+          <xsl:when test="parent::tr/following-sibling::tr and
+             not(@rowspan = count(parent::tr/following-sibling::tr) + 1)">1</xsl:when>
+          <xsl:otherwise>0</xsl:otherwise>
+        </xsl:choose>
+      </xsl:variable>
+
+      <xsl:if test="$rowborder = 1">
+        <xsl:attribute name="border-start-style">none</xsl:attribute>
+        <xsl:attribute name="border-end-style">none</xsl:attribute>
+        <xsl:attribute name="border-top-style">none</xsl:attribute>
+        <xsl:attribute name="border-bottom-style">
+          <xsl:value-of select="$table.frame.border.style"/>
+        </xsl:attribute>
+        <xsl:attribute name="border-bottom-width">
+          <xsl:value-of select="$table.frame.border.thickness"/>
+        </xsl:attribute>
+        <xsl:attribute name="border-bottom-color">
+          <xsl:value-of select="$table.frame.border.color"/>
+        </xsl:attribute>
+      </xsl:if>
+    </xsl:when>
+    <xsl:when test="$rules = 'all'">
+      <xsl:attribute name="border-start-style">none</xsl:attribute>
+      <xsl:attribute name="border-top-style">none</xsl:attribute>
+
+      <xsl:variable name="rowborder">
+        <xsl:choose>
+          <!-- If in thead and tbody has rows, add border -->
+          <xsl:when test="parent::tr/parent::thead/
+                          following-sibling::tbody/tr">1</xsl:when>
+          <!-- If in tbody and tfoot has rows, add border -->
+          <xsl:when test="parent::tr/parent::tbody/
+                          following-sibling::tfoot/tr">1</xsl:when>
+          <xsl:when test="parent::tr/parent::tbody/
+                          preceding-sibling::tfoot/tr">1</xsl:when>
+          <!-- If following rows, but not rowspan reaches last row -->
+          <xsl:when test="parent::tr/following-sibling::tr and
+             not(@rowspan = count(parent::tr/following-sibling::tr) + 1)">1</xsl:when>
+          <xsl:otherwise>0</xsl:otherwise>
+        </xsl:choose>
+      </xsl:variable>
+
+      <xsl:if test="$rowborder = 1">
+        <xsl:attribute name="border-bottom-style">
+          <xsl:value-of select="$table.frame.border.style"/>
+        </xsl:attribute>
+        <xsl:attribute name="border-bottom-width">
+          <xsl:value-of select="$table.frame.border.thickness"/>
+        </xsl:attribute>
+        <xsl:attribute name="border-bottom-color">
+          <xsl:value-of select="$table.frame.border.color"/>
+        </xsl:attribute>
+      </xsl:if>
+
+      <xsl:if test="following-sibling::*">
+        <!-- If not the last column, add border after -->
+        <xsl:attribute name="border-end-style">
+          <xsl:value-of select="$table.frame.border.style"/>
+        </xsl:attribute>
+        <xsl:attribute name="border-end-width">
+          <xsl:value-of select="$table.frame.border.thickness"/>
+        </xsl:attribute>
+        <xsl:attribute name="border-end-color">
+          <xsl:value-of select="$table.frame.border.color"/>
+        </xsl:attribute>
+      </xsl:if>
+    </xsl:when>
+    <xsl:when test="$rules = 'groups' and ancestor::thead 
+                    and not(parent::tr/following-sibling::tr)">
+      <xsl:attribute name="border-start-style">none</xsl:attribute>
+      <xsl:attribute name="border-end-style">none</xsl:attribute>
+      <xsl:attribute name="border-top-style">none</xsl:attribute>
+      <xsl:attribute name="border-bottom-style">
+        <xsl:value-of select="$table.frame.border.style"/>
+      </xsl:attribute>
+      <xsl:attribute name="border-bottom-width">
+        <xsl:value-of select="$table.frame.border.thickness"/>
+      </xsl:attribute>
+      <xsl:attribute name="border-bottom-color">
+        <xsl:value-of select="$table.frame.border.color"/>
+      </xsl:attribute>
+    </xsl:when>
+    <xsl:when test="$rules = 'groups' and ancestor::tfoot 
+                    and not(parent::tr/preceding-sibling::tr)">
+      <xsl:attribute name="border-start-style">none</xsl:attribute>
+      <xsl:attribute name="border-end-style">none</xsl:attribute>
+      <xsl:attribute name="border-top-style">none</xsl:attribute>
+      <xsl:attribute name="border-top-style">
+        <xsl:value-of select="$table.frame.border.style"/>
+      </xsl:attribute>
+      <xsl:attribute name="border-top-width">
+        <xsl:value-of select="$table.frame.border.thickness"/>
+      </xsl:attribute>
+      <xsl:attribute name="border-top-color">
+        <xsl:value-of select="$table.frame.border.color"/>
+      </xsl:attribute>
+    </xsl:when>
+  </xsl:choose>
+</xsl:template>
+
 <xsl:template match="caption" mode="htmlTable">
   <!-- Handled by formal.object.heading -->
 </xsl:template>
 </xsl:template>
 
 <xsl:template match="tbody" mode="htmlTable">
-  <fo:table-body border-bottom-width="0.25pt"
-                 border-bottom-style="solid"
-                 border-bottom-color="black"
-                 start-indent="0pt"
+  <fo:table-body start-indent="0pt"
                  end-indent="0pt">
     <xsl:apply-templates mode="htmlTable"/>
   </fo:table-body>
 </xsl:template>
 
-<xsl:template match="td" mode="htmlTable">
-  <xsl:variable name="bgcolor.pi">
-    <xsl:call-template name="pi.dbfo_bgcolor"/>
-  </xsl:variable>
-  <xsl:variable name="bgcolor">
-    <xsl:choose>
-      <xsl:when test="$bgcolor.pi != ''">
-        <xsl:value-of select="$bgcolor.pi"/>
-      </xsl:when>
-      <xsl:when test="string-length(@bgcolor) != 0">
-        <xsl:value-of select="@bgcolor"/>
-      </xsl:when>
-    </xsl:choose>
-  </xsl:variable>
-  <fo:table-cell xsl:use-attribute-sets="table.cell.padding">
-    <xsl:call-template name="table.cell.properties">
-      <xsl:with-param name="bgcolor.pi" select="$bgcolor"/>
-      <xsl:with-param name="rowsep.inherit" select="0"/>
-      <xsl:with-param name="colsep.inherit" select="0"/>
-    </xsl:call-template>
-
-    <xsl:if test="@colspan &gt; 1">
-      <xsl:attribute name="number-columns-spanned">
-        <xsl:value-of select="@colspan"/>
-      </xsl:attribute>
-    </xsl:if>
-
-    <xsl:if test="@rowspan &gt; 1">
-      <xsl:attribute name="number-rows-spanned">
-        <xsl:value-of select="@rowspan"/>
-      </xsl:attribute>
-    </xsl:if>
-
-    <fo:block>
-      <xsl:call-template name="table.cell.block.properties"/>
-      <xsl:apply-templates/>
-    </fo:block>
-  </fo:table-cell>
-</xsl:template>
-
 <xsl:template match="tfoot" mode="htmlTable">
   <fo:table-footer start-indent="0pt"
                    end-indent="0pt">
   </fo:table-footer>
 </xsl:template>
 
-<xsl:template match="th" mode="htmlTable">
+<xsl:template match="th|td" mode="htmlTable">
   <xsl:variable name="bgcolor.pi">
     <xsl:call-template name="pi.dbfo_bgcolor"/>
   </xsl:variable>
+
   <xsl:variable name="bgcolor">
     <xsl:choose>
       <xsl:when test="$bgcolor.pi != ''">
       </xsl:when>
     </xsl:choose>
   </xsl:variable>
-  <fo:table-cell xsl:use-attribute-sets="th.style table.cell.padding">
 
+  <xsl:variable name="align">
+    <xsl:call-template name="inherited.table.attribute">
+      <xsl:with-param name="entry" select="."/>
+      <xsl:with-param name="row" select="parent::tr"/>
+      <xsl:with-param name="attribute" select="'align'"/>
+    </xsl:call-template>
+  </xsl:variable>
+
+  <xsl:variable name="valign">
+    <xsl:call-template name="inherited.table.attribute">
+      <xsl:with-param name="entry" select="."/>
+      <xsl:with-param name="row" select="parent::tr"/>
+      <xsl:with-param name="attribute" select="'valign'"/>
+    </xsl:call-template>
+  </xsl:variable>
+
+  <fo:table-cell xsl:use-attribute-sets="table.cell.padding">
     <xsl:call-template name="table.cell.properties">
       <xsl:with-param name="bgcolor.pi" select="$bgcolor"/>
       <xsl:with-param name="rowsep.inherit" select="0"/>
+      <xsl:with-param name="align.inherit" select="$align"/>
+      <xsl:with-param name="valign.inherit" select="$valign"/>
       <xsl:with-param name="colsep.inherit" select="0"/>
     </xsl:call-template>
 
 </xsl:template>
 
 <xsl:template match="thead" mode="htmlTable">
-  <fo:table-header border-bottom-width="0.25pt"
-                   border-bottom-style="solid"
-                   border-bottom-color="black"
-                   start-indent="0pt"
-                   end-indent="0pt"
-                   font-weight="bold">
+  <fo:table-header start-indent="0pt"
+                   end-indent="0pt">
     <xsl:apply-templates mode="htmlTable"/>
   </fo:table-header>
 </xsl:template>
index 52879e6051cc27208e22fabe9b432757fa1a4799..a75d58280f7eb5383453db14f09338b4a9e9ce89 100644 (file)
@@ -48,6 +48,7 @@
 <!ENTITY current.docid SYSTEM "../params/current.docid.xml">
 <!ENTITY default.table.width SYSTEM "../params/default.table.width.xml">
 <!ENTITY default.table.frame SYSTEM "../params/default.table.frame.xml">
+<!ENTITY default.table.rules SYSTEM "../params/default.table.rules.xml">
 <!ENTITY default.units SYSTEM "../params/default.units.xml">
 <!ENTITY dingbat.font.family SYSTEM "../params/dingbat.font.family.xml">
 <!ENTITY double.sided SYSTEM "../params/double.sided.xml">
index 8e09e88efd645db2ca1abac0c280ca87de4cb9cb..468b171cedfe522ed946cbf38d52b0a396d016e6 100644 (file)
@@ -148,6 +148,7 @@ generate.section.toc.level;
 &default.table.width;
 &nominal.table.width;
 &default.table.frame;
+&default.table.rules;
 &table.cell.padding;
 &table.frame.border.thickness;
 &table.frame.border.style;
@@ -609,6 +610,7 @@ around all these parameters.</para>
 <src:fragref linkend="default.image.width.frag"/>
 <src:fragref linkend="default.table.width.frag"/>
 <src:fragref linkend="default.table.frame.frag"/>
+<src:fragref linkend="default.table.rules.frag"/>
 <src:fragref linkend="default.units.frag"/>
 <src:fragref linkend="dingbat.font.family.frag"/>
 <src:fragref linkend="double.sided.frag"/>
index b0b8758d80ef575fd1c53abd1ca32538d1f8e640..cec81c10f84c8bacfe82335f72a557e3c0b32219 100644 (file)
     <xsl:when test="self::table">
       <fo:block id="{$id}"
                 xsl:use-attribute-sets="table.properties">
-       <xsl:if test="$keep.together != ''">
-         <xsl:attribute name="keep-together.within-column">
-           <xsl:value-of select="$keep.together"/>
-         </xsl:attribute>
-       </xsl:if>
+        <xsl:if test="$keep.together != ''">
+          <xsl:attribute name="keep-together.within-column">
+            <xsl:value-of select="$keep.together"/>
+          </xsl:attribute>
+        </xsl:if>
         <xsl:if test="$placement = 'before'">
           <xsl:call-template name="formal.object.heading">
             <xsl:with-param name="placement" select="$placement"/>
   <xsl:variable name="rowsep">
     <xsl:choose>
       <!-- If this is the last row, rowsep never applies (except when 
-          the ancestor tgroup has a following sibling tgroup) -->
+           the ancestor tgroup has a following sibling tgroup) -->
       <xsl:when test="not(ancestor-or-self::row[1]/following-sibling::row
                           or ancestor-or-self::thead/following-sibling::tbody
                           or ancestor-or-self::tbody/preceding-sibling::tfoot)
-                         and not(ancestor::tgroup/following-sibling::tgroup)">
+                          and not(ancestor::tgroup/following-sibling::tgroup)">
         <xsl:value-of select="0"/>
       </xsl:when>
       <xsl:otherwise>
 
 <!-- ==================================================================== -->
 <xsl:template name="table.frame">
-  <xsl:variable name="frame">
+  <xsl:param name="frame">
     <xsl:choose>
       <xsl:when test="../@frame">
         <xsl:value-of select="../@frame"/>
       </xsl:when>
       <xsl:otherwise>all</xsl:otherwise>
     </xsl:choose>
-  </xsl:variable>
+  </xsl:param>
+
 
   <xsl:choose>
     <xsl:when test="$frame='all'">
         <xsl:value-of select="$table.frame.border.color"/>
       </xsl:attribute>
     </xsl:when>
+    <xsl:when test="$frame='lhs'">
+      <xsl:attribute name="border-start-style">
+        <xsl:value-of select="$table.frame.border.style"/>
+      </xsl:attribute>
+      <xsl:attribute name="border-end-style">none</xsl:attribute>
+      <xsl:attribute name="border-top-style">none</xsl:attribute>
+      <xsl:attribute name="border-bottom-style">none</xsl:attribute>
+      <xsl:attribute name="border-start-width">
+        <xsl:value-of select="$table.frame.border.thickness"/>
+      </xsl:attribute>
+      <xsl:attribute name="border-start-color">
+        <xsl:value-of select="$table.frame.border.color"/>
+      </xsl:attribute>
+    </xsl:when>
+    <xsl:when test="$frame='rhs'">
+      <xsl:attribute name="border-end-style">
+        <xsl:value-of select="$table.frame.border.style"/>
+      </xsl:attribute>
+      <xsl:attribute name="border-end-style">none</xsl:attribute>
+      <xsl:attribute name="border-top-style">none</xsl:attribute>
+      <xsl:attribute name="border-bottom-style">none</xsl:attribute>
+      <xsl:attribute name="border-end-width">
+        <xsl:value-of select="$table.frame.border.thickness"/>
+      </xsl:attribute>
+      <xsl:attribute name="border-end-color">
+        <xsl:value-of select="$table.frame.border.color"/>
+      </xsl:attribute>
+    </xsl:when>
     <xsl:when test="$frame='top'">
       <xsl:attribute name="border-start-style">none</xsl:attribute>
       <xsl:attribute name="border-end-style">none</xsl:attribute>
   <xsl:variable name="rowsep">
     <xsl:choose>
       <!-- If this is the last row, rowsep never applies (except when 
-          the ancestor tgroup has a following sibling tgroup) -->
+           the ancestor tgroup has a following sibling tgroup) -->
       <xsl:when test="not(ancestor-or-self::row[1]/following-sibling::row
                           or ancestor-or-self::thead/following-sibling::tbody
                           or ancestor-or-self::tbody/preceding-sibling::tfoot)
-                         and not(ancestor::tgroup/following-sibling::tgroup)">
+                          and not(ancestor::tgroup/following-sibling::tgroup)">
         <xsl:value-of select="0"/>
       </xsl:when>
       <!-- Check for morerows too -->
                        following-sibling::row) = @morerows )
                       and not (ancestor-or-self::thead/following-sibling::tbody
                        or ancestor-or-self::tbody/preceding-sibling::tfoot)
-                      and not(ancestor::tgroup/following-sibling::tgroup)">
+                       and not(ancestor::tgroup/following-sibling::tgroup)">
         <xsl:value-of select="0"/>
       </xsl:when>
 
           <xsl:value-of select="$bgcolor.pi"/>
         </xsl:attribute>
       </xsl:if>
-      <xsl:variable name="border" 
-                    select="(ancestor::table |
-                             ancestor::informaltable)[last()]/@border"/>
-      <xsl:if test="$border != '' and $border != 0">
-        <xsl:attribute name="border">
-          <xsl:value-of select="$table.cell.border.thickness"/>
-          <xsl:text> </xsl:text>
-          <xsl:value-of select="$table.cell.border.style"/>
-          <xsl:text> </xsl:text>
-          <xsl:value-of select="$table.cell.border.color"/>
+
+      <xsl:if test="$align.inherit != ''">
+        <xsl:attribute name="text-align">
+          <xsl:value-of select="$align.inherit"/>
         </xsl:attribute>
       </xsl:if>
+
+      <xsl:if test="$valign.inherit != ''">
+        <xsl:attribute name="display-align">
+          <xsl:choose>
+            <xsl:when test="$valign.inherit='top'">before</xsl:when>
+            <xsl:when test="$valign.inherit='middle'">center</xsl:when>
+            <xsl:when test="$valign.inherit='bottom'">after</xsl:when>
+            <xsl:otherwise>
+              <xsl:message>
+                <xsl:text>Unexpected valign value: </xsl:text>
+                <xsl:value-of select="$valign.inherit"/>
+                <xsl:text>, center used.</xsl:text>
+              </xsl:message>
+              <xsl:text>center</xsl:text>
+            </xsl:otherwise>
+          </xsl:choose>
+        </xsl:attribute>
+      </xsl:if>
+
+      <xsl:call-template name="html.table.cell.rules"/>
+
     </xsl:otherwise>
   </xsl:choose>