疑惑:在xsl里可以通过为同一个Topic建立多种模板吗?

jeskee 2003-10-16 11:58:08
我现在用jsp生成了一个xml文件:xml.jsp
其运行结果为:
<?xml version="1.0" encoding="gb2312" ?>
<?xml-stylesheet type="text/xsl" href="Style.xsl" ?>
<Topic>
<item>
<author xh="2">dddd</author>
<title>fsd</title>
<time>03/09/17</time>
</item>
<item>
<author xh="3">ffff</author>
<title>注意注意注意注意注意</title>
<time>03/09/17</time>
</item>
</Topic>

在Style.xsl中用<xsl:template match="Topic">建立了一个Topic的模板,接着后来的程序我又想再次为Topic建立一个不同的模板,请问可以吗?不想用<xsl:for-each>,谢谢


<xsl:template match="Topic">
<table width="500" border="1" align="center" cellpadding="1" cellspacing="1" bordercolordark="#ffffff" bordercolorlight="#ADAAAD">
<tr bgcolor="#FFCC99" align="center">
<td style="cursor:hand" onClick="taxis('blue_ID')">编号</td>
<td style="cursor:hand" onClick="taxis('blue_name')">作者</td>
<td style="cursor:hand" onClick="taxis('blue_text')">主题</td>
<td style="cursor:hand" onClick="taxis('blue_time')">发表时间</td>
</tr>
<xsl:apply-templates select="item" />
</table>
</xsl:template>
...全文
47 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
saucer 2003-10-16
  • 打赏
  • 举报
回复
if you are using XSLT, yes, you can use a template with a different mode:

<xsl:template match="Topic" mode="Whatever">
...
</xsl:template>


then, when you apply, you just

<xsl:apply-templates select="Topic" mode="Whatever" />
jeskee 2003-10-16
  • 打赏
  • 举报
回复
我找到错了,mode应该是针对<xsl:apply-templates select="item" />用的
THS,结贴
jeskee 2003-10-16
  • 打赏
  • 举报
回复
多谢,我试了一下还是有问题,再次麻烦。
代码在下面:
<XML id="data" >
<xsl:apply-templates select="Topic" mode="only" />
</XML>
<div id="Layer1" name="Layer1">
<xsl:apply-templates select="Topic" mode="Whatever" />
</div>


<xsl:template match="Topic" mode="Whatever" >
<table width="500" border="1" align="center" cellpadding="1" cellspacing="1" bordercolordark="#ffffff" bordercolorlight="#ADAAAD">
<tr bgcolor="#FFCC99" align="center">
<td style="cursor:hand" onClick="taxis('blue_ID')">编号</td>
<td style="cursor:hand" onClick="taxis('blue_name')">作者</td>
<td style="cursor:hand" onClick="taxis('blue_text')">主题</td>
<td style="cursor:hand" onClick="taxis('blue_time')">发表时间</td>
</tr>
<xsl:apply-templates select="item" />
</table>
</xsl:template>
<xsl:template match="Topic" mode="only" >
<xsl:element name="item">
<xsl:element name="author">
<xsl:attribute name="xh"><xsl:value-of select="item/author/@xh"/></xsl:attribute>
<xsl:value-of select="item/author" />
</xsl:element>
<xsl:element name="title">
<xsl:value-of select="item/title" />
</xsl:element>
<xsl:element name="time">
<xsl:value-of select="item/time" />
</xsl:element>
</xsl:element>
</xsl:template>
结果显示一条这样的结果,表格不见了:
dddd 03/09/17

8,906

社区成员

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

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