Note that there are some explanatory texts on larger screens.

plurals
  1. POConverting XHTML table to LaTeX using XSLT
    primarykey
    data
    text
    <p>I'm new in XSLT (v1.0) and I can't convert complex XHTML tables to LaTeX using XSLT.</p> <p>What I mean when I said complex tables, are tables with rows with different number of columns. In other words, <code>td</code> with <code>colspan</code>.</p> <p>i.e. (xhtml table)</p> <pre><code>&lt;table border="1" cellspacing="0" cellpadding="0"&gt; &lt;tr&gt; &lt;td valign="top" width="68" colspan="3"&gt; &lt;p&gt;Values&lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td valign="top" width="68"&gt; &lt;p&gt;95&lt;/p&gt; &lt;/td&gt; &lt;td valign="top" width="68"&gt; &lt;p&gt;169&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;/td&gt; &lt;td valign="top" width="68"&gt; &lt;p&gt;180&lt;/p&gt; &lt;p&gt; &lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; </code></pre> <p>What I'm doing in the XSL file is:</p> <pre><code>&lt;xsl:template match="xhtml:table[@border='1']"&gt; &lt;xsl:text&gt;\begin{center}&lt;/xsl:text&gt; &lt;xsl:text&gt;\begin{tabular}{&lt;/xsl:text&gt; &lt;xsl:for-each select="xhtml:tr[1]/*"&gt; &lt;xsl:text&gt;c&lt;/xsl:text&gt; &lt;xsl:if test="position() = last()"&gt; &lt;xsl:text&gt;}&amp;#10;&lt;/xsl:text&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; &lt;xsl:text&gt;\toprule&amp;#10;&lt;/xsl:text&gt; &lt;xsl:for-each select="xhtml:tr"&gt; &lt;xsl:if test="position() != 1"&gt; &lt;xsl:text&gt;\midrule&amp;#10;&lt;/xsl:text&gt; &lt;/xsl:if&gt; &lt;xsl:if test="position() = 2"&gt; &lt;xsl:text&gt;\midrule&amp;#10;&lt;/xsl:text&gt; &lt;/xsl:if&gt; &lt;xsl:for-each select="xhtml:td|xhtml:th"&gt; &lt;xsl:if test="name() = 'th'"&gt;{\bf &lt;/xsl:if&gt; &lt;xsl:apply-templates /&gt; &lt;xsl:if test="name() = 'th'"&gt;}&lt;/xsl:if&gt; &lt;xsl:if test="position() != last()"&gt; &lt;xsl:text&gt;&amp;amp;&lt;/xsl:text&gt; &lt;/xsl:if&gt; &lt;/xsl:for-each&gt; &lt;xsl:text&gt; \\&amp;#10;&lt;/xsl:text&gt; &lt;/xsl:for-each&gt; &lt;xsl:text&gt;\bottomrule&amp;#10;&lt;/xsl:text&gt; &lt;xsl:text&gt;\end{tabular}&amp;#10;&lt;/xsl:text&gt; &lt;xsl:text&gt;\end{center}&amp;#10;&lt;/xsl:text&gt; &lt;/xsl:template&gt; </code></pre> <p>But as you can see, this code just works for simple tables, without the colspan attribute. The code loops around the first <code>tr</code>, and for each <code>td</code>, it writes an "c". So, in the case above, it will only create a one column table.</p> <p>What I want to do is count the number of <code>td</code>, and the number of colspans if it exists, to create a correct table, with 3 columns.</p> <p>Does anyone knows how to do this? Thanks in advance.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload