I'm new in XSLT (v1.0) and I can't convert complex XHTML tables to LaTeX using XSLT.
What I mean when I said complex tables, are tables with rows with different number of columns. In other words, td
with colspan
.
i.e. (xhtml table)
<table border="1" cellspacing="0" cellpadding="0">
<tr>
<td valign="top" width="68" colspan="3"> <p>Values</p> </td>
</tr>
<tr>
<td valign="top" width="68"> <p>95</p> </td>
<td valign="top" width="68"> <p>169</p> <p> </p> </td>
<td valign="top" width="68"> <p>180</p> <p> </p> </td>
</tr>
</table>
What I'm doing in the XSL file is:
<xsl:template match="xhtml:table[@border='1']">
<xsl:text>egin{center}</xsl:text>
<xsl:text>egin{tabular}{</xsl:text>
<xsl:for-each select="xhtml:tr[1]/*">
<xsl:text>c</xsl:text>
<xsl:if test="position() = last()">
<xsl:text>} </xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text>oprule </xsl:text>
<xsl:for-each select="xhtml:tr">
<xsl:if test="position() != 1">
<xsl:text>midrule </xsl:text>
</xsl:if>
<xsl:if test="position() = 2">
<xsl:text>midrule </xsl:text>
</xsl:if>
<xsl:for-each select="xhtml:td|xhtml:th">
<xsl:if test="name() = 'th'">{f </xsl:if>
<xsl:apply-templates />
<xsl:if test="name() = 'th'">}</xsl:if>
<xsl:if test="position() != last()">
<xsl:text>&</xsl:text>
</xsl:if>
</xsl:for-each>
<xsl:text> \ </xsl:text>
</xsl:for-each>
<xsl:text>ottomrule </xsl:text>
<xsl:text>end{tabular} </xsl:text>
<xsl:text>end{center} </xsl:text>
</xsl:template>
But as you can see, this code just works for simple tables, without the colspan attribute. The code loops around the first tr
, and for each td
, it writes an "c". So, in the case above, it will only create a one column table.
What I want to do is count the number of td
, and the number of colspans if it exists, to create a correct table, with 3 columns.
Does anyone knows how to do this? Thanks in advance.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…