【发布时间】:2019-01-25 11:48:54
【问题描述】:
我有这样的表:
| 文字 | 文字 | 文字 | 文字 | 文字文字 | 文字 | 文字 | 文字 | 文字 |
|---|
我有这样的 XSLT 模板匹配(已删除属性匹配,因为此示例不需要它们):
<xsl:template match="colgroup">
<tgroup>
<xsl:apply-templates select="descendant::col | descendant::thead | descendant::tbody"/>
</tgroup>
</xsl:template>
<xsl:template match="col">
<colspec>
<xsl:apply-templates/>
</colspec>
</xsl:template>
<xsl:template match="thead">
<thead>
<xsl:apply-templates />
</thead>
</xsl:template>
<xsl:template match="tbody">
<tbody>
<xsl:apply-templates/>
</tbody>
</xsl:template>
我得到的结果是:
THEAD 和 TBODY 应该在 colgroup 中与 COL 元素处于同一级别,但我似乎无法让它合作。
【问题讨论】:
-
除了 Alochi 的回答之外,您的模板似乎都没有得到匹配,如果匹配“colgroup”,则输出应包含“tgroup”元素,但事实并非如此如果你的输出是准确的。您的实际 html 输入是否包含
xmlns="http://www.w3.org/1999/xhtml"形式的命名空间声明? -
您如何进行转换以及如何查看输出?如果您将输出发送到任何类型的 HTML 引擎,那么它将尝试重新组织表格以使其成为 HTML 有效的。