]> granicus.if.org Git - docbook-dsssl/commitdiff
Fix bug #1787140 HTML tables not handling attributes correctly.
authorBob Stayton <bobs@sagehill.net>
Wed, 11 Mar 2009 08:29:45 +0000 (08:29 +0000)
committerBob Stayton <bobs@sagehill.net>
Wed, 11 Mar 2009 08:29:45 +0000 (08:29 +0000)
xsl/html/formal.xsl
xsl/html/htmltbl.xsl

index c0f1204e1020424fc1e2341d7cd4473665ad5b14..c2bf5ae7cb76575ba5ca45961041611c8f4d5291 100644 (file)
     </xsl:when>
     <xsl:otherwise>
       <!-- do not use xsl:copy because of XHTML's needs -->
-      <table>
-        <xsl:copy-of select="@*[not(local-name()='id')]"/>
+      <xsl:element name="table" namespace="">
+        <xsl:apply-templates select="@*" mode="htmlTableAtt"/>
         <xsl:attribute name="id">
           <xsl:call-template name="object.id"/>
         </xsl:attribute>
         <xsl:call-template name="htmlTable"/>
-      </table>
+      </xsl:element>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>
       </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
-      <table>
-        <xsl:copy-of select="@*"/>
+      <xsl:element name="table" namespace="">
+        <xsl:apply-templates select="@*" mode="htmlTableAtt"/>
+        <xsl:attribute name="id">
+          <xsl:call-template name="object.id"/>
+        </xsl:attribute>
         <xsl:call-template name="htmlTable"/>
-      </table>
+      </xsl:element>
     </xsl:otherwise>
   </xsl:choose>
 </xsl:template>
index a5e4b15ff65fcd0261e78cf1212e1cd47dae4506..3f922b493ad6352877eb66947ca673ec6566fe9b 100644 (file)
 <!-- ==================================================================== -->
 
 <xsl:template match="colgroup" mode="htmlTable">
-  <xsl:copy>
-    <xsl:copy-of select="@*"/>
+  <xsl:element name="{local-name()}" namespace="">
+    <xsl:apply-templates select="@*" mode="htmlTableAtt"/>
     <xsl:apply-templates mode="htmlTable"/>
-  </xsl:copy>
+  </xsl:element>
 </xsl:template>
 
 <xsl:template match="col" mode="htmlTable">
-  <xsl:copy>
-    <xsl:copy-of select="@*"/>
-  </xsl:copy>
+  <xsl:element name="{local-name()}" namespace="">
+    <xsl:apply-templates select="@*" mode="htmlTableAtt"/>
+  </xsl:element>
 </xsl:template>
 
 <xsl:template match="caption" mode="htmlTable">
   <!-- do not use xsl:copy because of XHTML's needs -->
   <caption>  
-    <xsl:copy-of select="@*"/>
+    <xsl:apply-templates select="@*" mode="htmlTableAtt"/>
 
     <xsl:apply-templates select=".." mode="object.title.markup">
       <xsl:with-param name="allow-anchors" select="1"/>
 </xsl:template>
 
 <xsl:template match="tbody|thead|tfoot|tr" mode="htmlTable">
-  <xsl:element name="{name(.)}">
-    <xsl:copy-of select="@*"/>
+  <xsl:element name="{local-name(.)}">
+    <xsl:apply-templates select="@*" mode="htmlTableAtt"/>
     <xsl:apply-templates mode="htmlTable"/>
   </xsl:element>
 </xsl:template>
 
 <xsl:template match="th|td" mode="htmlTable">
-  <xsl:element name="{name(.)}">
-    <xsl:copy-of select="@*"/>
+  <xsl:element name="{local-name(.)}">
+    <xsl:apply-templates select="@*" mode="htmlTableAtt"/>
     <xsl:apply-templates/> <!-- *not* mode=htmlTable -->
   </xsl:element>
 </xsl:template>
 
+<!-- don't copy through DocBook-specific attributes on HTML table markup -->
+<!-- default behavior is to not copy through because there are more
+     DocBook attributes than HTML attributes -->
+<xsl:template mode="htmlTableAtt" match="@*"/>
+
+<!-- copy these through -->
+<xsl:template mode="htmlTableAtt"
+              match="@abbr
+                   | @align
+                   | @axis
+                   | @bgcolor
+                   | @border
+                   | @cellpadding
+                   | @cellspacing
+                   | @char
+                   | @charoff
+                   | @class
+                   | @colspan
+                   | @dir
+                   | @frame
+                   | @headers
+                   | @height
+                   | @lang
+                   | @nowrap
+                   | @onclick
+                   | @ondblclick
+                   | @onkeydown
+                   | @onkeypress
+                   | @onkeyup
+                   | @onmousedown
+                   | @onmousemove
+                   | @onmouseout
+                   | @onmouseover
+                   | @onmouseup
+                   | @rowspan
+                   | @rules
+                   | @span
+                   | @style
+                   | @summary
+                   | @title
+                   | @valign
+                   | @valign
+                   | @width
+                   | @xml:lang">
+  <xsl:copy-of select="."/>
+</xsl:template>
+
+<xsl:template match="@span|@rowspan|@colspan" mode="htmlTableAtt">
+  <!-- No need to copy through the DTD's default value "1" of the attribute -->
+  <xsl:if test="number(.) != 1">
+    <xsl:attribute name="{local-name(.)}">
+      <xsl:value-of select="."/>
+    </xsl:attribute>
+  </xsl:if>
+</xsl:template>
+
+<!-- map floatstyle to HTML float values -->
+<xsl:template match="@floatstyle" mode="htmlTableAtt">
+  <xsl:attribute name="style">
+    <xsl:text>float: </xsl:text>
+    <xsl:choose>
+      <xsl:when test="contains(., 'left')">left</xsl:when>
+      <xsl:when test="contains(., 'right')">right</xsl:when>
+      <xsl:when test="contains(., 'start')">
+        <xsl:value-of select="$direction.align.start"/>
+      </xsl:when>
+      <xsl:when test="contains(., 'end')">
+        <xsl:value-of select="$direction.align.end"/>
+      </xsl:when>
+      <xsl:when test="contains(., 'inside')">
+        <xsl:value-of select="$direction.align.start"/>
+      </xsl:when>
+      <xsl:when test="contains(., 'outside')">
+        <xsl:value-of select="$direction.align.end"/>
+      </xsl:when>
+      <xsl:when test="contains(., 'before')">none</xsl:when>
+      <xsl:when test="contains(., 'none')">none</xsl:when>
+    </xsl:choose>
+    <xsl:text>;</xsl:text>
+  </xsl:attribute>
+</xsl:template>
+
 </xsl:stylesheet>