xml - XSL 转换后 LaTeX 表不适合线宽

标签 xml xslt xhtml latex xslt-1.0

我正在尝试使用 XSLT(版本 1.0)将表格从 XHTML 转换为 LaTeX,但该表格不适合文档的有用区域(宽度 - 16cm)。

没有 colspan 的表格恰好适合文档的有用区域,但有 colspan 的表格超出了这个区域。

我不知道我做错了什么。

例子

XHMTL 表

<table border="1" cellspacing="0" cellpadding="0">
    <tr>
        <td colspan="2"> <strong>LOREM</strong></td> 
        <td colspan="10"><strong>IPSUM DOLOR SIT AMET</strong></td> 
    </tr>
    <tr>
        <td colspan="2"></td>
        <td><strong>consectetuer</strong></td> 
        <td><strong>adipiscing</strong></td> 
        <td><strong>elit</strong></td> 
        <td><strong>Aenean</strong></td> 
        <td><strong>commodo</strong></td> 
        <td><strong>ligula</strong></td> 
        <td><strong>eget</strong></td> 
        <td><strong>dolor</strong></td> 
        <td><strong>Aenean</strong></td> 
        <td><strong>massa</strong></td> 
    </tr>
    <tr>
        <td><strong>Cum</strong></td> 
        <td>sociis</td> 
        <td>natoque</td> 
        <td>penatibus</td> 
        <td>magnis</td> 
        <td>parturient</td> 
        <td>montes</td> 
        <td>nascetur</td> 
        <td>ridiculus</td> 
        <td>Donec</td> 
        <td>felis</td> 
        <td><strong>ultricies</strong></td> 
    </tr>
</table>

xsl代码

<xsl:template match="xhtml:table">
    <xsl:text>\begin{center}&#10;</xsl:text>
    <xsl:text>\begin{tabulary}{\linewidth}{</xsl:text>

    <xsl:variable name="total_columns">
        <xsl:value-of select="sum(xhtml:tr[1]/*/@colspan) + count(xhtml:tr[1]/*[not(@colspan)])"/>
    </xsl:variable>

    <xsl:text>*{</xsl:text>
    <xsl:value-of select="$total_columns"/>
    <xsl:text>}{C}}&#10;</xsl:text>

    <xsl:text>\toprule&#10;</xsl:text>

    <xsl:for-each select="xhtml:tr">
        <xsl:if test="position() != 1">
            <xsl:text>\midrule&#10;</xsl:text>
        </xsl:if>

        <xsl:if test="position() = 2">
            <xsl:text>\midrule&#10;</xsl:text>
        </xsl:if>

        <xsl:for-each select="xhtml:td|xhtml:th">
            <xsl:if test="self::xhtml:th">\bfseries</xsl:if>

            <xsl:choose>
                <xsl:when test="@colspan">
                    <xsl:if test="current()/@colspan&gt;=0">
                        \multicolumn{<xsl:value-of select="current()/@colspan"/>}{
                        >{\centering\arraybackslash}m{
                        <xsl:value-of select="((16 div $total_columns) * current()/@colspan)"/>cm}}{
                    </xsl:if>
                </xsl:when>
            </xsl:choose>

            <xsl:apply-templates/>

            <xsl:choose>
                <xsl:when test="@colspan">
                    <xsl:if test="current()/@colspan&gt;=0">}</xsl:if>
                </xsl:when>
            </xsl:choose>

            <xsl:if test="position() != last()">
                <xsl:text>&amp;</xsl:text>
            </xsl:if>
        </xsl:for-each>

        <xsl:if test="position()!=last()">\\&#10;</xsl:if>
    </xsl:for-each>

    <xsl:text>\\&#10;\bottomrule</xsl:text>
    <xsl:text>&#10;\end{tabulary}&#10;</xsl:text>
    <xsl:text>\end{center}</xsl:text>

</xsl:template>

最佳答案

I'm not sure what is wrong with the LaTeX, the table is generated, but even with the width limited to 16cm, the table exceed the area. Then, this is not necessarily an XSLT problem. Not exactly on topic, but you might want to use TeXML (getfo.org/texml) for tranforming XHTML>LaTeX with XSLT (where TeXML is intermediate step).

关于xml - XSL 转换后 LaTeX 表不适合线宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20121194/

相关文章:

xml - XSLT 应用模板选择中的 "@*|node()"是什么意思?

c - 如何使用 XSL 翻译 C 结构中的 XML 文档

xml - 获取名称中包含 '#' 的 XML 元素

c# - Linq To XML - 使用 XDocument 和创建对象列表

php - 使用 PHP/MySQL 应用程序时是否有理由使用 XML/XSLT?

html - HTML 标签上的背景位置不起作用

html - 填充行内元素的顶部和底部

xml - func Encode(),编码xml的所有部分

java - java中使用JDOM解析XML(getChildren方法不返回List)

css - 如何使重叠 Flash 下的 HTML 易于访问