我正在研究CALS表并陷入困境。我在下表中。
<?xml version="1.0" encoding="UTF-8"?>
<table frame="all">
<tgroup cols="2">
<colspec colnum="1" colname="col1" colwidth="2*"/>
<colspec colnum="2" colname="col2" colwidth="16*"/>
<tbody>
<row>
<entry align="center" valign="top" colname="col1" colsep="1" rowsep="1"><para><content-style font-style="bold">A</content-style></para></entry>
<entry align="left" valign="top" colname="col2" colsep="1" rowsep="1"><para><content-style font-style="bold">Board Matters</content-style></para></entry>
</row>
<row>
<entry align="center" valign="top" colname="col1" colsep="1" rowsep="1"><para></para></entry>
<entry align="left" valign="top" colname="col2" colsep="1" rowsep="1"><para></para></entry>
</row>
<row>
<entry align="center" valign="top" colname="col1" colsep="1" rowsep="1"><para><content-style font-style="bold">2</content-style></para></entry>
<entry align="left" valign="top" colname="col2" colsep="1" rowsep="1"><para><content-style font-style="bold">Board composition and balance</content-style> <content-style font-style="bolditalic">(strong and independent board with no dominant</content-style><content-style font-style="bolditalic" format="strikethrough">e</content-style> <content-style font-style="bolditalic">individual(s))</content-style></para></entry>
</row>
</tbody>
</tgroup>
</table>
以及下面的XSLT。
<xsl:template name="table" match="table">
<xsl:if test="./title/page">
<xsl:apply-templates select="./title/page"/>
</xsl:if>
<div class="figure">
<div class="figure-title">
<xsl:value-of select="./title"/>
</div>
</div>
<table class="frame-{current()/@frame}">
<xsl:apply-templates select="child::node()[not(self::title)]"/>
</table>
</xsl:template>
<xsl:template match="tgroup">
<xsl:if test="not(preceding-sibling::tgroup)">
<xsl:if test="@colsep|@rowsep|@align|cols">
</xsl:if>
</xsl:if>
<colgroup>
<xsl:apply-templates select=".//colspec" />
</colgroup>
<xsl:apply-templates select="child::node()[not(self::colspec|self::tfoot/*)]" />
</xsl:template>
<xsl:template name="tbody" match="tgroup/tbody">
<tbody>
<xsl:for-each select="current()/row">
<xsl:call-template name="row" />
</xsl:for-each>
</tbody>
<xsl:if test="preceding-sibling::tfoot">
<tfoot class="foot">
<xsl:apply-templates select="preceding-sibling::tfoot"/>
</tfoot>
</xsl:if>
</xsl:template>
<xsl:template name="thead" match="tgroup/thead">
<thead>
<xsl:for-each select="current()/row">
<tr>
<xsl:for-each select="current()/entry">
<xsl:call-template name="headentry" />
</xsl:for-each>
</tr>
</xsl:for-each>
</thead>
</xsl:template>
<xsl:template match="box">
<div class="box">
<div class="title">
<xsl:value-of select="./title"/>
</div>
<xsl:apply-templates select="child::node()[not(self::title)]"/>
</div>
</xsl:template>
<xsl:template name="colspec" match="colspec">
<xsl:variable name="b">
<xsl:value-of select="sum(../colspec/number(substring-before(@colwidth,'*')))"/>
</xsl:variable>
<col class="colname-{current()/@colname} colwidth-{concat(format-number( number(substring-before(@colwidth,'*')) div $b * 100,'##'),'%')}" />
<xsl:text disable-output-escaping="yes"><![CDATA[</col>]]></xsl:text>
</xsl:template>
<xsl:template name="row" match="row">
<xsl:if test="./entry/*/page">
<xsl:apply-templates select="./entry/*/page"/>
</xsl:if>
<xsl:choose>
<xsl:when test="parent::tfoot">
<tr>
<xsl:for-each select="current()/entry">
<xsl:call-template name="entry" />
</xsl:for-each>
</tr>
</xsl:when>
<xsl:otherwise>
<tr>
<xsl:for-each select="current()/entry">
<xsl:call-template name="entry" />
</xsl:for-each>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="entry" name="entry">
<xsl:choose>
<xsl:when test="./@namest">
<xsl:variable name="namest" select="@namest"/>
<xsl:variable name="nameend" select="@nameend"/>
<xsl:variable name="namestPos" select="count(ancestor::tgroup/colspec[@colname=$namest]/preceding-sibling::colspec)"/>
<xsl:variable name="nameendPos" select="count(ancestor::tgroup/colspec[@colname=$nameend]/preceding-sibling::colspec)"/>
<td colspan="{$nameendPos - $namestPos + 1}" align="{@align}">
<xsl:apply-templates select="child::node()[not(self::page)]"/>
</td>
</xsl:when>
<xsl:when test="@align and ./@morerows">
<td align="{@align}" rowspan="{number(./@morerows)+1}">
<xsl:for-each select="para">
<div class="para">
<xsl:apply-templates select="child::node()[not(self::page)]"/>
</div>
</xsl:for-each>
</td>
</xsl:when>
<xsl:when test="./@morerows and not(./@align)">
<td rowspan="{number(./@morerows)+1}">
<xsl:for-each select="para">
<div class="para">
<xsl:apply-templates select="child::node()[not(self::page)]"/>
</div>
</xsl:for-each>
</td>
</xsl:when>
<xsl:when test="not(./@morerows) and ./@align">
<td align="{@align}">
<xsl:for-each select="para">
<div class="para">
<xsl:apply-templates select="child::node()[not(self::page)]"/>
</div>
</xsl:for-each>
</td>
</xsl:when>
<xsl:otherwise>
<td>
<xsl:for-each select="para">
<div class="para">
<xsl:apply-templates select="child::node()[not(self::page)]"/>
</div>
</xsl:for-each>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="headentry">
<xsl:choose>
<xsl:when test="@align">
<td class="align-{@align}">
<xsl:if test="translate(current()/@namest,'col','') != translate(current()/@nameend,'col','')">
<xsl:variable name="colspan">
<xsl:value-of select="xs:integer(translate(current()/@nameend,'col','')) - xs:integer(translate(current()/@namest,'col','')) + 1" />
</xsl:variable>
<xsl:attribute name="colspan">
<xsl:value-of select="$colspan">
</xsl:value-of>
</xsl:attribute>
</xsl:if>
<xsl:for-each select="para">
<div class="para">
<xsl:apply-templates></xsl:apply-templates>
</div>
</xsl:for-each>
</td>
</xsl:when>
<xsl:otherwise>
<td>
<xsl:if test="translate(current()/@namest,'col','') != translate(current()/@nameend,'col','')">
<xsl:variable name="colspan">
<!-- <xsl:value-of select="translate(current()/@nameend,'col','') - translate(current()/@namest,'col','') + 1" />-->
</xsl:variable>
<xsl:attribute name="colspan">
<xsl:value-of select="$colspan">
</xsl:value-of>
</xsl:attribute>
</xsl:if>
<xsl:for-each select="para">
<div class="para">
<xsl:apply-templates></xsl:apply-templates>
</div>
</xsl:for-each>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
这里当我运行XSLT时一切都很好,但我遇到了以下XML部分的问题。
<row>
<entry align="center" valign="top" colname="col1" colsep="1" rowsep="1"><para></para></entry>
<entry align="left" valign="top" colname="col2" colsep="1" rowsep="1"><para></para></entry>
</row>
在输出中我需要一个空行,它正在生成,但看起来更像是两条线,没有间隙。如下图所示。
但实际上我需要在这些行之间留下一些差距,如下所示。
请让我知道如何完成此操作,我想知道如何在我的XSLT中使用colsep
和rowsep
。
由于
答案 0 :(得分:1)
在空para
中添加不间断空格作为内容。更像是
<row>
<entry align="center" valign="top" colname="col1" colsep="1" rowsep="1"><para> </para></entry>
<entry align="left" valign="top" colname="col2" colsep="1" rowsep="1"><para> </para></entry>
</row>