假设我有一个表格的XML表
<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>
Run Code Online (Sandbox Code Playgroud)
我希望使用XSLT转换为LaTeX(我在其他地方偷了这个例子).我想要的结果是
\documentclass{memoir}
\usepackage{multirow}
\begin{document}
\begin{tabular}{*{10}{c}}
First name & Bill Gates &\\
\multirow{2}{*}{Telephone:}
& 555 77 854 &\\
& 555 77 855 &
\end{tabular}
\end{document}
Run Code Online (Sandbox Code Playgroud)
在大多数情况下,两种表格格式之间存在公平的一对一对应关系.因此,这在很大程度上非常有效:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<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[not(@rowspan) and not(@colspan)]">
<xsl:apply-templates/> &
</xsl:template>
<xsl:template …Run Code Online (Sandbox Code Playgroud)