使用XSLT验证html样式表数据

使用XSLT验证html样式表数据,xslt,html-table,xslt-2.0,Xslt,Html Table,Xslt 2.0,我需要能够用html样式的表数据检查xml,以确保它是“矩形”的。例如,这是矩形(2x2) 下面是一组糟糕的表格示例,其中不清楚如何处理它们 <!-- bad, looks like spanned cells are included but more cells in row 1 than 2 --> <table> <tr> <td colspan="2">Foo</td> <td/> &l

我需要能够用html样式的表数据检查xml,以确保它是“矩形”的。例如,这是矩形(2x2)

下面是一组糟糕的表格示例,其中不清楚如何处理它们

<!-- bad, looks like spanned cells are included but more cells in row 1 than 2 -->
<table>
  <tr>
    <td colspan="2">Foo</td>
    <td/>
    <td rowspan="2">Bar</td>
    <td>BAD</td>
  </tr>
  <tr>
    <td>Baz</td>
    <td>Qux</td>
    <td/>
  </tr>
</table>

<!-- bad, looks like spanned cells are omitted but more cells in row 1 than 2 -->
<table>
  <tr>
    <td colspan="2">Foo</td>
    <td rowspan="2">Bar</td>
    <td>BAD</td>
  </tr>
  <tr>
    <td>Baz</td>
    <td>Qux</td>
  </tr>
</table>

<!-- bad, can't tell if spanned cells are included or omitted -->
<table>
  <tr>
    <td colspan="2">Foo</td>
    <td rowspan="2">Bar</td>
  </tr>
  <tr>
    <td>Baz</td>
    <td>Qux</td>
    <td/>
  </tr>
</table>

<!-- bad, looks like spanned cells are omitted but a non-emtpy cell is overspanned -->
<table>
  <tr>
    <td colspan="2">Foo</td>
    <td rowspan="2">Bar</td>
  </tr>
  <tr>
    <td>Baz</td>
    <td>Qux</td>
    <td>BAD</td>
  </tr>
</table>

福
酒吧
坏的
巴兹
库克斯
福
酒吧
坏的
巴兹
库克斯
福
酒吧
巴兹
库克斯
福
酒吧
巴兹
库克斯
坏的
对于这个问题,我已经有了一个XSLT2.0解决方案,它涉及到将数据规范化为“包含跨单元格”样式,然后进行验证。然而,我的解决方案很麻烦,对于面积大于1000个单元格的表,它的性能开始很差。我的规范化和验证例程包括在单元格上按顺序迭代,并传递一个单元格参数,该参数应该由spans创建,并在我在表中传递它们的坐标时插入它们。我对他们两个都不满意


我正在寻找有关实现此验证的更聪明方法的建议,希望在大型表上有更好的性能配置文件。我需要解释
th
td
,但从示例中省略了
th
,为了简单起见,在任何答案中都可以包含或忽略它们。我没有检查
thead
tbody
和/或
tfoot
是否具有相同的宽度,这也可以包括或省略。我目前正在使用XSLT 2.0,但如果3.0解决方案明显优于2.0中实现的解决方案,我会对其感兴趣。

我认为这种问题不适合XSLT,尤其是当您必须处理非常大的表时


我建议使用过程性语言开发一个解决方案—可能使用XSLT对XML进行预处理或后处理。

关于“包含为空的跨单元格”:是否可以假设任何空单元格都表示一个连续的跨单元格(或者您如何称呼它)?这不是“真实的”HTML,是吗?因为空单元格不应该在那里,对吗?@ThomasW不可能有真正空的空单元格,
@rowspan
@colspan
是存在跨度的唯一指示。不,这不是真的HTML,实际上,有一些不同的模式具有与HTML表模型非常相似的表。但是,您无法判断该表是否退化,因为您不知道某个单元格是否真的为空或某个跨度的占位符。我当前的解决方案处理整个表,以查看该表是否至少有一个空单元格每一个跨度,如果有,那么我将表视为包含空单元格,如果空单元格少于跨度,那么我将其视为不包含跨度的空单元格。
<table>
  <tr>
    <td>Foo</td>
    <td>Bar</td>
  </tr>
  <tr>
    <td>Baz</td>
  </tr>
</table>
<!-- good (3x2), spanned cells included -->
<table>
  <tr>
    <td colspan="2">Foo</td>
    <td/>
    <td rowspan="2">Bar</td>
  </tr>
  <tr>
    <td>Baz</td>
    <td>Qux</td>
    <td/>
  </tr>
</table>

<!-- also good (3x2), spanned cells omitted -->
<table>
  <tr>
    <td colspan="2">Foo</td>
    <td rowspan="2">Bar</td>
  </tr>
  <tr>
    <td>Baz</td>
    <td>Qux</td>
  </tr>
</table>
<!-- bad, looks like spanned cells are included but more cells in row 1 than 2 -->
<table>
  <tr>
    <td colspan="2">Foo</td>
    <td/>
    <td rowspan="2">Bar</td>
    <td>BAD</td>
  </tr>
  <tr>
    <td>Baz</td>
    <td>Qux</td>
    <td/>
  </tr>
</table>

<!-- bad, looks like spanned cells are omitted but more cells in row 1 than 2 -->
<table>
  <tr>
    <td colspan="2">Foo</td>
    <td rowspan="2">Bar</td>
    <td>BAD</td>
  </tr>
  <tr>
    <td>Baz</td>
    <td>Qux</td>
  </tr>
</table>

<!-- bad, can't tell if spanned cells are included or omitted -->
<table>
  <tr>
    <td colspan="2">Foo</td>
    <td rowspan="2">Bar</td>
  </tr>
  <tr>
    <td>Baz</td>
    <td>Qux</td>
    <td/>
  </tr>
</table>

<!-- bad, looks like spanned cells are omitted but a non-emtpy cell is overspanned -->
<table>
  <tr>
    <td colspan="2">Foo</td>
    <td rowspan="2">Bar</td>
  </tr>
  <tr>
    <td>Baz</td>
    <td>Qux</td>
    <td>BAD</td>
  </tr>
</table>