【发布时间】:2012-03-09 07:18:54
【问题描述】:
我是新手,我正在尝试在
具体来说,我想将
问题:
这是我的xml文档,适用部分。无法更改文档结构。
<table>
<tgroup>
<thead>
<trow>
<tcell>Column Head Text</tcell>
<tcell>Column Head Text</tcell>
</trow>
</thead>
<tbody>
<trow>
<tcell>Cell Text</tcell>
<tcell>Cell Text</tcell>
</trow>
</tbody>
</tgroup>
</table>
我想使用 XSL/XPath 生成带有标题行和正文行的表。我的 XSL 样式表如下所示:
<xsl:template match="/">
<html>
<body>
<xsl:apply templates />
</body>
</html>
</xsl:template>
<xsl:template match="table">
<table>
<xsl:apply-templates />
</table>
</xsl:template>
<xsl:template match="tgroup">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="thead">
<thead>
<xsl:apply-templates />
</thead>
</xsl:template>
<xsl:template match="tbody">
<tbody>
<xsl:apply-templates />
</tbody>
</xsl:template>
<xsl:template match="trow">
<tr>
<xsl:apply-templates />
</tr>
</xsl:template>
<!-- MY TROUBLE STARTS HERE -->
<xsl:template match="tcell">
<xsl:choose>
<xsl:when test="current()!=descendant::tbody">
<th>
<xsl:value-of select="."/>
</th>
</xsl:when>
<xsl:otherwise>
<td>
<xsl:value-of select="."/>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
任何帮助将不胜感激。
示例 html 输出
<table>
<tgroup>
<thead>
<tr>
<th>Column Head Text</th>
<th>Column Head Text</th>
<tr>
</thead>
<tbody>
<tr>
<td>Cell Text</td>
<td>Cell Text</td>
</tr>
</tbody>
</tgroup>
</table>
谢谢, M_66
【问题讨论】:
-
请显示所需的输出xml
-
所需的 xml 输出将是:
<table><br></table>