求助:XSLT

贝壳里的鱼 2008-10-29 05:04:45
小弟我刚开始学XSLT 遇到个问题 请各位大侠帮忙:
下面是xml文件
<NewDataSet>
<Table>
<BoardId>1</BoardId>
<ParentID>-1</ParentID>
<BoardType>论坛一</BoardType>
<CreateTime>2008-10-29T15:37:36.967+08:00</CreateTime>
</Table>
<Table>
<BoardId>2</BoardId>
<ParentID>-1</ParentID>
<BoardType>论坛二</BoardType>
<CreateTime>2008-10-29T15:37:36.98+08:00</CreateTime>
</Table>
<Table>
<BoardId>3</BoardId>
<ParentID>1</ParentID>
<BoardType>测试产品论坛版面一</BoardType>
<CreateTime>2008-10-29T15:37:36.98+08:00</CreateTime>
</Table>
<Table>
<BoardId>4</BoardId>
<ParentID>2</ParentID>

<BoardType>测试版面一二</BoardType>
<CreateTime>2008-10-29T15:37:36.98+08:00</CreateTime>
</Table>
</NewDataSet>
ParentID=-1 的两个table是论坛的根版面,下面parentID等于BoardID的是他的子论坛。我想在XSL文件中按照这种层次关系把他们给显示出来。根版面现在已经用循环显示出来了,就是他们的子版面我不知道应该如何放在他相应的根论坛下。求高手帮忙,谢谢啦·
...全文
46 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
孟子E章 2008-11-01
  • 打赏
  • 举报
回复
你 可以类似这样
<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="a.xsl"?>
<NewDataSet>
<Table>
<BoardId>1</BoardId>
<ParentID>-1</ParentID><BoardType>论坛一 </BoardType>
<CreateTime>2008-10-29T15:37:36.967+08:00 </CreateTime>
</Table>
<Table>
<BoardId>2</BoardId>
<ParentID>-1</ParentID><BoardType>论坛二 </BoardType>
<CreateTime>2008-10-29T15:37:36.98+08:00 </CreateTime>
</Table>
<Table>
<BoardId>3</BoardId>
<ParentID>1</ParentID><BoardType>测试产品论坛版面一 </BoardType>
<CreateTime>2008-10-29T15:37:36.98+08:00 </CreateTime>
</Table>
<Table>
<BoardId>5</BoardId>
<ParentID>1</ParentID><BoardType>测试产品论坛版面一 </BoardType>
<CreateTime>2008-10-29T15:37:36.98+08:00 </CreateTime>
</Table>
<Table>
<BoardId>4</BoardId>
<ParentID>2</ParentID>
<BoardType>测试版面一二 </BoardType>
<CreateTime>2008-10-29T15:37:36.98+08:00 </CreateTime>
</Table>
</NewDataSet>



<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="/NewDataSet/Table[ParentID = '-1']">
<div style="border:1px solid red">
<div style="border:1px solid #0f0;padding-left:20px">
<xsl:value-of select="BoardType"/>
</div>
<xsl:call-template name="ch">
<xsl:with-param name="childBoard" select="BoardId"></xsl:with-param>
</xsl:call-template>
</div>
</xsl:for-each>
</body>
</html>
</xsl:template>
<xsl:template name="ch">
<xsl:param name="childBoard"></xsl:param>
<xsl:for-each select="/NewDataSet/Table[ParentID = $childBoard]">
<div style="border:1px solid #0ff;padding-left:20px">
<xsl:value-of select="BoardType"/>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

8,906

社区成员

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

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