Skip to content

transpect/htmltables

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

htmltables

Library for normalizing HTML tables (adding “physical grid” coordinates to each cell). Requires xslt-util

Description

This implements Andrew J Welch's Table Normalization in XSLT 2.0 in an XSLT function:

<xsl:template match="*[*:tr]">
    <xsl:sequence select="htmltable:normalize(.)" />
</xsl:template>

Consider an XML or XHTML document containing HTML tables

<table>
  <tbody>
    <tr>
      <td>a</td>
      <td rowspan="2">b</td>
    </tr>
    <tr>
      <td>c</td>
    </tr>
    <tr>
      <td colspan="2">d</td>
    </tr>
  </tbody>
</table>

Applying the XSLT function htmltable:normalize() will add virtual cells for each colspan and rowspan.

-------------         -------------          
|  a  |  b  |         |  a  |  b  |             
-------     -         -------------
|  c  |     |   -->   |  c  |  b  |
-------------         -------------
|     d     |         |  d  |  d  |
-------------         -------------

After the normalization, each cell contains data attributes which state the former position in the original table.

<table>         
  <tbody>
    <tr>
      <td data-rownum="1" data-colnum="1">a</td>
      <td rowspan="2" data-rownum="1" data-colnum="2">b</td>
    </tr>
    <tr>
      <td data-rownum="2" data-colnum="1">c</td>
      <td rowspan="1" data-rowspan-part="2" data-rownum="2" data-colnum="2">b</td>
    </tr>
    <tr>
      <td colspan="2" data-colspan-part="1" data-rownum="3" data-colnum="1">d</td>
      <td colspan="2" data-colspan-part="2" data-rownum="3" data-colnum="2">d</td>
    </tr>
  </tbody>
</table>

About

Replace colspan and rowspan with virtual cells

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 6