请教:XSLT+XML转换HTML问题

csdnmoonstar 2003-08-21 05:07:09
预期的效果是产生一个表格,但是现在只有表头,其余是文本,哪位DX帮忙解释一下?
test.xml文件如下:
<?xml version="1.0" encoding="gb2312" ?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<xml>
<Main>

</Main>

<people name="p11" sex="m" age="13">
<memo><![CDATA[....contents1]]></memo>
</people>

<people name="p21" sex="f" age="23">
<memo><![CDATA[....contents2]]></memo>
</people>

<people name="p31" sex="f" age="33">
<memo><![CDATA[....contents3]]></memo>
</people>

<people name="p41" sex="m" age="43">
<memo><![CDATA[....contents4]]></memo>
</people>
</xml>

test.xsl文件如下:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" indent="yes"/>

<xsl:template match="Main">

<html>
<head>
</head>

<body>

<table border="1" cellspacing="1" cellpadding="2" align="center" width="100%">
<tr valign="bottom">
<td width='30%'>att a</td>
<td width='30%'>att b</td>
<td width='40%'>att c</td>
</tr>
<xsl:apply-templates />
</table>
</body>
</html>

</xsl:template>

<xsl:template match="people">
<tr valign="top">
<xsl:choose>
<xsl:when test="@sex='m'">
<td><xsl:value-of select="@name"/></td>
<td><font color="ff0000"><xsl:value-of select="@sex"/></font></td>
<td><xsl:value-of select="@age"/></td>
</xsl:when>

<xsl:when test="@sex='f'">
<td><xsl:value-of select="@name"/></td>
<td><font color="0000ff"><xsl:value-of select="@sex"/></font></td>
<td><xsl:value-of select="@age"/></td>
</xsl:when>
</xsl:choose>
</tr>
</xsl:template>

</xsl:stylesheet>
...全文
95 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
月光易水 2003-08-21
  • 打赏
  • 举报
回复
xpath错误
不指定从根节点开始解析,则自动匹配节点模板

xml中 Main与people为兄弟节点,依次执行显示
xsl中 Main模板 中 <xsl:apply-templates /> 匹配其子节点,执行结果自然为空

修改
a.
<xsl:template match="Main">
==>
<xsl:template match="/">
<xsl:apply-templates select="xml/Main" />
</xsl:template>
<xsl:template match="Main">

b. Main模板中
<xsl:apply-templates />
==>
<xsl:apply-templates select="../people" />


:_)

8,906

社区成员

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

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