Nicolas Gallegos Nicolas Gallegos - 1 month ago 14
HTML Question

XSLT Count total number of rows in a Table

I'm working with XML that contains HTML Table with rowspan. I need to get the total amount of cols and rows of this table, I need to work this with xslt to do a transformation.
I'm trying to do something like this :

<xsl:value of select="count(./tr) - count(./tr/td/@rowspan > 1 and ./tr/td =1)"</xsl:value-of>


Of course, this doesn't work because I have some
<tr>
with more than one
<td>
. I need to count only when this two conditions are checked. I assume xslt looks ALL the
<tr>
and doesn't check in the same where the first condition is true.

Any help/suggestion?

In this Example, we have 5 , but the "real" count of should be 4. (The HTML output has 4 rows).

<table border="2">
<tr>
<td align="left" colspan="3" valign="top">
text
</td>
</tr>
<tr>
<td align="left" rowspan="3" valign="top">
text
</td>
</tr>
<tr>
<td align="left" rowspan="2" valign="top">
text
</td>
<td align="left" valign="top">
text
</td>
</tr>
<tr>
<td align="left" valign="top">
text
</td>
</tr>
<tr>
<td align="left" valign="top">
text
</td>
<td align="left" valign="top">
text
</td>
</tr>
</table>

Answer

I need to count all the rows with rowspan > 1, that have more than one td.

There is only one like that:

<xsl:value-of select="count(table/tr[td/@rowspan > 1 and count(td) > 1] )"/>