<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://purl.oclc.org/dsdl/schematron">
<ns prefix="h" uri="http://www.w3.org/1999/xhtml"/>
<pattern id="tables">
<rule context="h:th[@scope]">
<assert id="tables.th-scope-enum" role="error" test="@scope='row' or @scope='col' or @scope='rowgroup' or @scope='colgroup'">
A th element's scope attribute must be one of row, col, rowgroup, or colgroup.
</assert>
</rule>
</pattern>
<pattern id="tables-colspan-max">
<rule context="h:td[@colspan] | h:th[@colspan]">
<assert id="tables.colspan-max" role="error" test="not(number(@colspan) > 1000)">
The value of the "colspan" attribute must be less than or equal to 1000.
</assert>
</rule>
</pattern>
<pattern id="tables-rowspan-max">
<rule context="h:td[@rowspan] | h:th[@rowspan]">
<assert id="tables.rowspan-max" role="error" test="not(number(@rowspan) > 65534)">
The value of the "rowspan" attribute must be less than or equal to 65534.
</assert>
</rule>
</pattern>
<pattern id="tables-span-max">
<rule context="h:col[@span] | h:colgroup[@span]">
<assert id="tables.span-max" role="error" test="not(number(@span) > 1000)">
The value of the "span" attribute must be less than or equal to 1000.
</assert>
</rule>
</pattern>
<pattern id="tables-td-role">
<rule context="h:td[@role]">
<assert id="tables.td-role-in-table" role="error"
test="not(ancestor::h:table[1][not(@role) or @role = 'table' or @role = 'grid' or @role = 'treegrid'])">
The "role" attribute must not be used on a "td" element which has a "table" ancestor with no "role" attribute, or with a "role" attribute whose value is "table", "grid", or "treegrid".
</assert>
</rule>
</pattern>
<pattern id="tables-headers">
<rule context="h:td[@headers] | h:th[@headers]">
<let name="me" value="."/>
<let name="table" value="ancestor::h:table[1]"/>
<assert id="tables.headers-ref-th" role="error"
test="id(@headers)[self::h:th and ancestor::h:table[1] = $table]">
The "headers" attribute on the element refers to an ID, but there is no "th" element with that ID in the same table.
</assert>
</rule>
</pattern>
<pattern id="tables-row-no-cells">
<rule context="h:tr[not(h:td) and not(h:th)]">
<assert id="tables.row-no-cells" role="error" test="false()">
A row of a row group has no cells beginning on it.
</assert>
</rule>
</pattern>
<pattern id="tables-row-width-vs-column-markup">
<rule context="h:tr[ancestor::h:table[1]/h:colgroup]">
<let name="table" value="ancestor::h:table[1]"/>
<let name="row-width"
value="count(h:td[not(@colspan)]) + count(h:th[not(@colspan)]) + sum(h:td/@colspan) + sum(h:th/@colspan)"/>
<let name="column-count-from-markup"
value="count($table/h:colgroup/h:col[not(@span)]) + sum($table/h:colgroup/h:col/@span) + count($table/h:colgroup[not(h:col)][not(@span)]) + sum($table/h:colgroup[not(h:col)]/@span)"/>
<assert id="tables.row-width-not-less-than-column-markup" role="error"
test="$row-width >= $column-count-from-markup">
A table row was narrower than the column count established using column markup.
</assert>
<assert id="tables.row-width-not-exceeding-column-markup" role="error"
test="$row-width <= $column-count-from-markup">
A table row exceeded the column count established using column markup.
</assert>
</rule>
</pattern>
<pattern id="tables-row-width-vs-first-row">
<rule context="h:tr[not(ancestor::h:table[1]/h:colgroup)]">
<let name="table" value="ancestor::h:table[1]"/>
<let name="first-row"
value="($table/h:tr | $table/h:thead/h:tr | $table/h:tbody/h:tr | $table/h:tfoot/h:tr)[1]"/>
<let name="row-width"
value="count(h:td[not(@colspan)]) + count(h:th[not(@colspan)]) + sum(h:td/@colspan) + sum(h:th/@colspan)"/>
<let name="first-row-width"
value="count($first-row/h:td[not(@colspan)]) + count($first-row/h:th[not(@colspan)]) + sum($first-row/h:td/@colspan) + sum($first-row/h:th/@colspan)"/>
<assert id="tables.row-width-not-less-than-first-row" role="warning"
test="$row-width >= $first-row-width">
A table row was narrower than the column count established by the first row.
</assert>
<assert id="tables.row-width-not-exceeding-first-row" role="warning"
test="$row-width <= $first-row-width">
A table row exceeded the column count established by the first row.
</assert>
</rule>
</pattern>
</schema>