首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >从CALS中剥离空柱

从CALS中剥离空柱
EN

Stack Overflow用户
提问于 2016-04-12 15:08:49
回答 1查看 50关注 0票数 0

我有一个类似的问题在这里回答,Strip empty columns from calstable model

本质上,这也是一个稍微复杂一些的问题:我在多个XML文件中有一堆CALS模型表。其中有些有一个空的最终列,如本例中所示

<table frame="none"> <tgroup cols="4" colsep="0" rowsep="0"> <colspec colname="1" colnum="1" colwidth="75pt"/> <colspec colname="2" colnum="2" colwidth="63pt" align="center"/> <colspec colname="3" colnum="3" colwidth="63pt" align="center"/> <colspec colname="4" colnum="4" colwidth="63pt"/> <thead> <row valign="bottom"> <entry> </entry> <entry>No. 9</entry> <entry>No. 10</entry> <entry> </entry> </row> </thead> <tbody> <row> <entry>Max. size:</entry> <entry>10.5 m.</entry> <entry>6.7 m.</entry> <entry> </entry> </row> <row> <entry>Length:</entry> <entry>210 m.</entry> <entry>100 m.</entry> <entry> </entry> </row> <row> <entry>Depth:</entry> <entry>11.0</entry> <entry>7.0</entry> <entry> </entry> </row> </tbody> </tgroup> </table>

我想删除最后的空栏。另一篇文章的答案解决了许多例子。但是,当表在结构中使用合并的单元格时,就无法工作了。

跨行将被编码为

<row> <entry namest="1" nameend="3">Notes: This table is short</entry> <entry> </entry> </row>

我需要对另一个解决方案进行哪些调整,以解释跨行问题?

提亚

EN

回答 1

Stack Overflow用户

发布于 2016-04-14 04:51:17

我从JLRishe修改了样式表

代码语言:javascript
复制
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>

    <!-- This key will allow us to select all the entries in a column based on their
       column  number -->
    <xsl:key name="kColumn" match="entry"
        use="count(. | preceding-sibling::entry[not(@namest)]) 
        + count(preceding-sibling::entry[@namest])
        + sum(preceding-sibling::entry/@nameend)
        - sum(preceding-sibling::entry/@namest)"/>

    <xsl:template match="@* | node()">
        <xsl:copy>
            <xsl:apply-templates select="@* | node()" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="tgroup">
        <xsl:copy>
            <xsl:apply-templates select="@*" />
            <!-- Select colspecs whose column isn't all blank -->
            <xsl:apply-templates 
                select="colspec[key('kColumn', position())[normalize-space(.)]]" />
            <xsl:apply-templates select="node()[not(self::colspec)]" />
        </xsl:copy>
    </xsl:template>

    <xsl:template match="colspec">
        <colspec colname="{position()}" colnum="{position()}">
            <xsl:apply-templates 
                select="@*[local-name() != 'colname' and local-name() != 'colnum']" />
            <xsl:apply-templates select="node()" />
        </colspec>
    </xsl:template>

    <!-- Omit entries that belong to all-blank columns -->
    <xsl:template match="entry[not(key('kColumn', count(. | preceding-sibling::entry[not(@namest)]) 
        + count(preceding-sibling::entry[@namest])
        + sum(preceding-sibling::entry/@nameend)
        - sum(preceding-sibling::entry/@namest))[normalize-space(.)])]" />
</xsl:stylesheet>

我已经用@namest@nameend做了几个测试。如果存在@morerows,我不确定这段代码是否有效。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36577273

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档