Suppose I have an XML table of the form
<table>
<tr>
<td>First Name:</td>
<td>Bill Gates</td>
</tr>
<tr>
<td rowspan="2">Telephone:</td>
<td>555 77 854</td>
</tr>
<tr>
<td>555 77 855</td>
</tr>
</table>
that I wish to convert to LaTeX using XSLT (I stole this example elsewhere). The result I want is
\documentclass{memoir}
\usepackage{multirow}
\begin{document}
\begin{tabular}{*{10}{c}}
First name \cr Bill Gates \cr\\
\multirow{2}{*}{Telephone:}
\cr 555 77 854 \cr\\
\cr 555 77 855 \cr
\end{tabular}
\end{document}
For the most part, there is a fair one-to-one-correspondence between the two table formats. Thus this works quite well for the most part:
<xsl:stylesheet version="2.0" xmlns:xsl="http://ift.tt/tCZ8VR">
<xsl:output method="text" omit-xml-declaration="yes" encoding="UTF-8"/>
<xsl:template match="/">
\documentclass{memoir}
\usepackage{multirow}
\begin{document}
<xsl:apply-templates/>
\end{document}
</xsl:template>
<xsl:template match="table>
\begin{tabular}{*{10}{c}}
<xsl:apply-templates/>
\end{tabular}
</xsl:template>
<xsl:template match="tr">
<xsl:apply-templates />\\
</xsl:template>
<xsl:template match="td[no(@rowspan) and no(@colspan)]">
<xsl:apply-templates/> \cr
</xsl:template>
<xsl:template match="td[no(@colspoan)]">
\multirow{<xsl:value-of select="@colspan"/>}{*}{<xsl:apply-templates/>} \cr
</xsl:template>
<xsl:template match="td[no(@rowspan)">
\multicolumn{<xsl:value-of select="@colspan"/>}{l}{<xsl:apply-templates/>} \cr
</xsl:template>
<xsl:template match="td">
\multirow{<xsl:value-of select="@rowspan"/>}{*}{\multicolumn{<xsl:value-of select="@colspan"/>}}{l}{<xsl:apply-templates/>} \cr
</xsl:template>
</xsl:stylesheet>
The problem is the \crs. In LaTeX, you need one in the beginning of the third row, where the spanned cell is. This is not the case in the XML table. How can I get around this problem?
No comments:
Post a Comment