创建Cals表

时间:2013-12-02 11:37:17

标签: xslt xslt-2.0

我有以下XML文档,其中必须创建一些cals表。

<table frame="none">
    <tgroup cols="5" align="left" colsep="1" rowsep="1">
        <colspec colwidth="20pt" colname="c1"/>
        <colspec colwidth="70pt" colname="c2"/>
        <colspec colwidth="10pt" colname="c3"/>
        <colspec colwidth="20pt" colname="c4"/>
        <colspec colwidth="75pt" colname="c5"/>
        <thead>
            <row>
                <entry>
                    <para>Item</para>
                </entry>
                <entry align="center">
                    <para>Injury</para>
                </entry>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para>Percentage of loss of earning capacity</para>
                </entry>
                <entry>
                    <para/>
                </entry>
            </row>
        </thead>
        <tbody>
            <row>
                <entry>
                    <para>1.</para>
                </entry>
                <entry>
                    <para>Loss of 2 limbs ...................................................................</para>
                </entry>
                <entry morerows="7">
                    <para>}</para>
                </entry>
                <entry morerows="7">
                    <para>100</para>
                </entry>
                <entry morerows="7">
                    <para></para>
                </entry>
            </row>
            <row>
                <entry>
                    <para>2.</para>
                </entry>
                <entry>
                    <para>Loss of both hands or of all fingers and both thumbs ...</para>
                </entry>
            </row>
            <row>
                <entry>
                    <para>3.</para>
                </entry>
                <entry>
                    <para>Loss of both feet ................................................................</para>
                </entry>
            </row>
            <row>
                <entry>
                    <para>4.</para>
                </entry>
                <entry>
                    <para>Total loss of sight ...............................................................</para>
                </entry>
            </row>
            <row>
                <entry>
                    <para>5.</para>
                </entry>
                <entry>
                    <para>Total paralysis ....................................................................</para>
                </entry>
            </row>
            <row>
                <entry>
                    <para>6.</para>
                </entry>
                <entry>
                    <para>Injuries resulting in being permanently bedridden .......</para>
                </entry>
            </row>
            <row>
                <entry>
                    <para>7.</para>
                </entry>
                <entry>
                    <para>Paraplegia ..........................................................................</para>
                </entry>
            </row>
            <row>
                <entry>
                    <para>8.</para>
                </entry>
                <entry>
                    <para>Any other injury causing permanent total disablement ...</para>
                </entry>
            </row>
            <row>
                <entry>
                    <para>9.</para>
                </entry>
                <entry>
                    <para>Loss of arm at shoulder ....................................................</para>
                </entry>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para>75</para>
                </entry>
                <entry>
                    <para>80 (preferred hand)</para>
                </entry>
            </row>
            <row>
                <entry>
                    <para>10.</para>
                </entry>
                <entry>
                    <para>Ankylosis of shoulder joint—</para>
                </entry>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para/>
                </entry>
            </row>
            <row>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para>in optimum position .....................................................</para>
                </entry>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para>35</para>
                </entry>
                <entry>
                    <para/>
                </entry>
            </row>
            <row>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para>in worst position ............................................................</para>
                </entry>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para>55</para>
                </entry>
                <entry>
                    <para/>
                </entry>
            </row>
            <row>
                <entry>
                    <para>11.</para>
                </entry>
                <entry>
                    <para>Loss of arm between elbow and shoulder .......................</para>
                </entry>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para>75</para>
                </entry>
                <entry>
                    <para>80 (preferred hand)</para>
                </entry>
            </row>
            <row>
                <entry>
                    <para>12.</para>
                </entry>
                <entry>
                    <para>Loss of arm at elbow ..........................................................</para>
                </entry>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para>75</para>
                </entry>
                <entry>
                    <para>80 (preferred hand)</para>
                </entry>
            </row>
            <row>
                <entry>
                    <para>13.</para>
                </entry>
                <entry>
                    <para>Ankylosis of the elbow joint—</para>
                </entry>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para/>
                </entry>
            </row>
            <row>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para>in optimum position .....................................................</para>
                </entry>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para>30</para>
                </entry>
                <entry>
                    <para/>
                </entry>
            </row>
            <row>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para>in worst position ............................................................</para>
                </entry>
                <entry>
                    <para/>
                </entry>
                <entry>
                    <para>50</para>
                </entry>
                <entry>
                    <para/>
                </entry>
            </row>
            <row>
                <entry>
                    <para>14.</para>
                </entry>
            </row>
        </tbody>
    </tgroup>
</table>

这里我要创建一个表格,如下图enter image description here

所示

我知道直接询问代码不是一个好主意,我试过普通表(已经完成),但我真的不知道如何在xslt中做一个cals表。请让我知道如何实现这些cals表。

由于

1 个答案:

答案 0 :(得分:1)

你在评论中说你正在寻找HTML输出 - 你开始使用的输入XML具有正确的结构,可以直接转换为具有1-1元素名称映射的HTML表,你只需要将源格式的morerows="n"转换为HTML中的rowspan="n+1"

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  <xsl:strip-space elements="*" />
  <xsl:output method="html" indent="yes" />

  <!-- these nodes have the same names in HTML -->
  <xsl:template match="table | thead | tbody">
    <xsl:copy><xsl:apply-templates /></xsl:copy>
  </xsl:template>

  <!-- row becomes tr -->
  <xsl:template match="row">
    <tr><xsl:apply-templates /></tr>
  </xsl:template>

  <!-- entry becomes td -->
  <xsl:template match="entry">
    <td><xsl:apply-templates select="@morerows|node()" /></td>
  </xsl:template>

  <xsl:template match="entry/@morerows">
    <xsl:attribute name="rowspan" select="1 + ." />
  </xsl:template>
</xsl:stylesheet>

我们依赖于没有显式模板的节点的默认模板规则,在元素的情况下递归处理子节点,在文本节点的情况下输出文本。

您已经标记了XSLT 2.0的问题但是对于记录这几乎是一个XSLT 1.0样式表,您唯一需要更改的是xsl:attribute不会使用select 1.0,所以代替<xsl:attribute name="rowspan" select="..." />,您需要<xsl:attribute name="rowspan"><xsl:value-of select="..." /></xsl:attribute>