【发布时间】:2021-08-30 00:15:32
【问题描述】:
我试图在命名时计算总和 tgroup/colspec/@colwidth nameend 出现在 entry 元素中。
我运行下面的 XSLT 代码,但没有出现预期的输出,请 帮助我提前谢谢!
输入 XML:
<?xml version="1.0" encoding="UTF-8"?> <table> <tgroup cols="9"> <colspec colwidth="60*"/> <colspec colwidth="1*"/> <colspec colwidth="1*"/> <colspec colwidth="12*"/> <colspec colwidth="1*"/> <colspec colwidth="1*"/> <colspec colwidth="1*"/> <colspec colwidth="12*"/> <colspec colwidth="1*"/> </tgroup> <thead> <row> <entry colname="col1"> </entry> <entry colname="col2"/> <entry colname="col3" namest="col3" nameend="col8"> <b>My content here</b> </entry> <entry colname="col9"/> </row> </thead> </table>我的 XSLT 代码
<xsl:output method="xml"/>
<xsl:template match="table">
<table width="90%">
<xsl:if test="tgroup/thead">
<thead>
<xsl:for-each select="tgroup/thead/row">
<tr>
<xsl:for-each select="entry">
<xsl:variable name="entrycol" select="@colname"/>
<td>
<xsl:if test="(@namest ne '') and (@nameend ne '')">
<xsl:attribute name="colspan">
<xsl:value-of select="number(substring-after(@nameend,'col')) - number(substring-after(@namest,'col')) + 1"/>
</xsl:attribute>
</xsl:if>
<xsl:attribute name="style">
<xsl:if test="@colname = ancestor::tgroup/colspec/@colname">
<xsl:variable name="kk1" select="format-number(sum(ancestor::tgroup/colspec/@colwidth/xs:decimal(translate(., '*', ''))), '#.##')"/>
<xsl:text>width:</xsl:text>
<xsl:value-of select="concat(format-number(ancestor::tgroup/colspec[@colname = $entrycol][1]/number(translate(@colwidth, '*', '')) div number($kk1) * 100,'#.##'), '%')"/>
<xsl:text>; </xsl:text>
</xsl:if>
</xsl:attribute>
<xsl:if test="tgroup/tbody">
<tbody>
<tr></tr>
</tbody>
</xsl:if>
</td>
</xsl:for-each>
</tr>
</xsl:for-each>
</thead>
</xsl:if>
</table>
</xsl:template>
</xsl:stylesheet>
预期输出
<?xml version="1.0" encoding="UTF-8"?> <table width="90%"> <thead> <tr> <td style="width:60%;"> <p> </p> </td> <td style="width:1%;"> <p></p> </td> <td colspan="6" style="width:28%;"> <p> <b>My content here</b> </p> </td> <td style="width:1%;"> <p></p> </td> </tr> </thead> <tbody> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> <tr> </tr> </tbody> </table>
【问题讨论】:
-
什么是表格输入格式,任何众所周知或定义明确的表格格式?什么是输出格式,HTML?您是否检查过是否存在可在两种格式之间转换的库?
-
嗨@MartinHonnen:输入表格式为DITA xml,输出格式为HTML
-
请帮我解决这个问题
-
但 DITA OT 肯定包含将 DITA 转换为 HTML 的所有代码。
-
检查dita-ot.org是否已经完成了这项工作。
标签: xslt-2.0 xquery-3.0