怎样指定用调用模板生成的表格的id呢?多谢!

luoxiang2000 2005-02-25 11:46:43
例如:
<xsl:for-each select="Record">
<xsl:apply-templates select="SchemaSet"/>
</xsl:for-each>

<xsl:template match="SchemaSet">
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="font" id="表格名称(第一个表格是tab01,以后类推?)">
<xsl:for-each select="Schema">
<tr>
<td/>
</tr>
</xsl:for-each>
</table>
</xsl:template>
...全文
128 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
luoxiang2000 2005-02-27
  • 打赏
  • 举报
回复
高定了,谢谢!原来是我xml中间右一个重复节点!
luoxiang2000 2005-02-27
  • 打赏
  • 举报
回复
还是有问题?
其实我最终的想法是前一个表格点击后控制某一个tr表格的显示/隐藏,但是不知道那里有错误,按照您的方法试了,不行???有没有什么好的方法调试诺?多谢多谢!
<xsl:for-each select="Record">
<xsl:call-template name="table">
<xsl:with-param name="id" select="position()"/>
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:for-each>

<xsl:template name="table">
<xsl:param name="id"/>
<xsl:param name="node"/>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="font" id="tab{$id}">
<xsl:for-each select="$node/Schema">
<tr id="tr1_{$id}" onClick="document.all.tr2_{$id}.style.display='none';">
<td/>
</tr>
<tr id="tr2_{$id}"/>
</xsl:for-each>
</table>
</xsl:template>
luoxiang2000 2005-02-26
  • 打赏
  • 举报
回复
我想了一个笨办法,就是在节点处增加一个一个属性DisplayId,然后:id="layer1_"<xsl:value-of select="@DisplayId"/>_td1"。
比如我第一个节点的DisplayId=1,那么我要得到的id为:layer1_1_td1
不过用上面的代码根本就不行,报错亚!!!???
我又不想直接把DisplayId=layer1_1_td1,谢谢!

另外,这个办法就算行,我觉得也不是很好,有没有更好的办法?这样好像也不行:id="layer1_"<xsl:value-of select="index()"/>"_td1"
yjs_lh 2005-02-26
  • 打赏
  • 举报
回复
建议使用命名模板

<xsl:for-each select="Record">
<xsl:call-template name="table">
<xsl:with-param name="id" select="position()"/>
<xsl:with-param name="node" select="."/>
</xsl:call-template>
</xsl:for-each>

<xsl:template name="table">
<xsl:param name="id"/>
<xsl:param name="node"/>
<table width="100%" border="0" cellpadding="0" cellspacing="0" class="font" id="tab{$id}">
<xsl:for-each select="$node/Schema">
<tr>
<td/>
</tr>
</xsl:for-each>
</table>
</xsl:template>

不过,这样得到的id中没有0。如果实在需要,可以使用<xsl:if>、<xsl:choose>或XSL字符串函数等生成中间的0。

8,909

社区成员

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

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