(急!!!)对于相同的节点名,但位置不同,我想让它生成相同的HTML标签,但有不同的属性.我该怎么办?

peppi 2002-09-26 04:21:33
XML如下:
<a>
<b>
<c>1</c>
<c>2</c>
</b>
<b>
<c>3</c>
</b>
</a>

XSL如下:

<xsl:template match="b">
<tr>
<xsl:apply-templates select="c"/>
</tr>
</xsl:template>

<xsl:template match="c">
<td align="center">
<xsl:value-of select="."/>
td>
</xsl:template>

<xsl:template match="ITEM[position()=3]">
<td align="center">
<xsl:attribute name="colspan">
4
</xsl:attribute>
<xsl:value-of select="."/>
</td>
</xsl:template>


我的本意是想让最后一个节点c单独一行,而且在中间显示,我怎么不能让它到中间去呢?该怎么办?
...全文
80 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
outside 2002-09-26
  • 打赏
  • 举报
回复
如果你c最多只有2个则代码如下

<xsl:template match="/">
<table border="1" width="300">
<xsl:apply-templates />
</table>
</xsl:template>

<xsl:template match="b">
<tr>
<xsl:choose>
<xsl:when test="count(c)=2">
<xsl:apply-templates select="c" mode="a" />
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="c" mode="b" />
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:template>

<xsl:template match="c" mode="a">
<td align="center">
<xsl:value-of select="."/>
</td>
</xsl:template>

<xsl:template match="c" mode="b">
<td colspan="2" align="center">
<xsl:value-of select="."/>
</td>
</xsl:template>
peppi 2002-09-26
  • 打赏
  • 举报
回复
我用choose也不大懂,望各位指点一二:
<xsl:template match="c">
<xsl:choose>
<xsl:when test="position() != 3">
<td align="center">
<xsl:value-of select="."/>
</td>
</xsl:when>
<xsl:otherwise>
<td align="center">
<xsl:attribute name="colspan">
4
</xsl:attribute>
xsl:value-of select="."/>
</td>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

也是不行,问题在哪呢?它只能分行显示,但始终不能把第二行放到中间.

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧