我在尝试获取每个 td 的宽度时遇到问题,我目前在列宽中得到一个空白值,如何获取每个 td 的值。
<xsl:template match="table">
<fo:table table-layout="fixed">
<xsl:call-template name="tokenize-style"/>
<!-- Calculate the table cols... -->
<xsl:for-each select="tbody/tr[1]/td">
<fo:table-column>
<xsl:attribute name="column-width">
<xsl:value-of select="@width"></xsl:value-of>
</xsl:attribute>
</fo:table-column>
</xsl:for-each>
<xsl:apply-templates select="*|text()"/>
</fo:table>
</xsl:template>
<xsl:template match="tbody">
<fo:table-body>
<xsl:apply-templates select="*|text()"/>
</fo:table-body>
</xsl:template>
基于 HTML ->
<table class="te-tablerenderer" style="width: 170mm; text-align: left;">
<tbody style="text-align: left;">
<tr class="" style="text-align: left;">
<td style="width: 141px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(255, 255, 255); border-right-color: rgb(255, 255, 255); border-bottom-color: rgb(255, 255, 255); border-left-color: rgb(255, 255, 255); "> </td>
<td style="width: 143px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(255, 255, 255); border-right-color: rgb(255, 255, 255); border-bottom-color: rgb(255, 255, 255); border-left-color: rgb(255, 255, 255); ">
<b>Postcode:</b>
</td>
<td class="GENTICS_Table_Cell_active"
style="width: 325px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(255, 255, 255); border-right-color: rgb(255, 255, 255); border-bottom-color: rgb(255, 255, 255); border-left-color: rgb(255, 255, 255); ">
djnds fnjksdnf
</td>
<td style="width: 33px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-color: rgb(255, 255, 255); border-right-color: rgb(255, 255, 255); border-bottom-color: rgb(255, 255, 255); border-left-color: rgb(255, 255, 255); "> </td>
</tr>
</tbody>
</table>
注意:这是我想要获取元素的所有样式时调用的模板:
<xsl:template name="tokenize-style">
<xsl:param name="pString" select="string(@style)"/>
<xsl:choose>
<xsl:when test="not($pString)"/>
<xsl:when test="contains($pString,';')">
<xsl:call-template name="tokenize-style">
<xsl:with-param name="pString"
select="substring-before($pString,';')"/>
</xsl:call-template>
<xsl:call-template name="tokenize-style">
<xsl:with-param name="pString"
select="substring-after($pString,';')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="{normalize-space(substring-before($pString,':'))}">
<xsl:value-of select="normalize-space(substring-after($pString,':'))"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
输出
<fo:table table-layout="fixed" width="170mm" text-align="left">
<fo:table-column column-width=""/>
<fo:table-column column-width=""/>
<fo:table-column column-width=""/>
<fo:table-column column-width=""/>
<fo:table-body>
<fo:table-row>
<fo:table-cell padding-start="1pt" padding-end="1pt" padding-before="1pt" padding-after="1pt"
padding-top="1pt"
padding-bottom="1pt">
<fo:block> </fo:block>
</fo:table-cell>
(..ETC)
注意列宽是空白...