【发布时间】:2021-11-01 10:38:17
【问题描述】:
@colwidth 的值与tblW/@w:w 的值相同,请帮助我
Xml 输入:
<tbl>
<tblPr>
<tblW w="5000" type="pct"/>
</tblPr>
<tblGrid>
<gridCol/>
<gridCol/>
<gridCol/>
</tblGrid>
<tr>
<tc>
<tcPr>
<tcW w="2450" type="pct"/>
</tcPr>
<p>Content here</p>
</tc>
<tc>
<tcPr>
<tcW w="50" type="pct"/>
</tcPr>
<p>Content here</p>
</tc>
<tc>
<tcPr>
<tcW w="2500" type="pct"/>
</tcPr>
<p>Payment at Maturity:</p>
</tc>
</tr>
</tbl>
输出:
<table>
<tgroup cols="3">
<colspec colname="c1" colnum="1" colwidth="24.5%.5%25.0%"/>
<colspec colname="c2" colnum="2" colwidth="24.5%.5%25.0%"/>
<colspec colname="c3" colnum="3" colwidth="24.5%.5%25.0%"/>
<tbody>
<row>
<entry>
<p>Content Here</p>
</entry>
</row>
<!--here all content will come-->
</tbody>
</tgroup>
</table>
Xslt 代码:
<xsl:choose>
<xsl:when test="not(@w:w)">
<xsl:attribute name="colwidth">
<xsl:for-each select="ancestor::w:tbl/w:tr/w:tc/w:tcPr/w:tcW">
<xsl:value-of select="concat(format-number(@w:w div 100,'#.##'), '%')"/>
</xsl:for-each>
</xsl:attribute>
</xsl:when>
<xsl:otherwise>
<xsl:attribute name="colwidth">
<xsl:value-of select="concat(format-number(@w:w div number(ancestor::w:tbl/w:tblPr/w:tblW/@w:w) * 100,'#.##'), '%')"/>
</xsl:attribute>
</xsl:otherwise>
</xsl:choose>
预期输出:
<table>
<tgroup cols="3">
<colspec colname="c1" colnum="1" colwidth="24.5%"/>
<colspec colname="c2" colnum="2" colwidth="0.5%"/>
<colspec colname="c3" colnum="3" colwidth="25.0%"/>
<tbody>
<row>
<entry>
<p>Content Here</p>
</entry>
</row>
<!-- All content will come here-->
</tbody>
</tgroup>
</table>
【问题讨论】: