明輝手游網(wǎng)中心:是一個免費提供流行視頻軟件教程、在線學(xué)習(xí)分享的學(xué)習(xí)平臺!

我也貼一個,用的時候只要配制好xml文件就行了,連程序都不用改

[摘要]使用時需要加載XSLT模塊,程序下載地址:http://xiaocon.51.net/tree/tree.zip演示地址:http://xiaocon.51.net/tree/tree.htm或ht...
使用時需要加載XSLT模塊,程序下載地址:http://xiaocon.51.net/tree/tree.zip
演示地址:

http://xiaocon.51.net/tree/tree.htm



http://xiaocon.51.net/tree/navi.xml

51.net上不支持xslt :(
程序文件:
===========================================================
<?php
$xslstring = implode('',file("navigator.xsl"));
$xmlstring = implode('',file("navi.xml"));
$arguments = array(
 '/_xml' => $xmlstring,
 '/_xsl' => $xslstring
);

$xh = xslt_create();

$result = xslt_process($xh, 'arg:/_xml', 'arg:/_xsl', NULL, $arguments);
if ($result) {
print $result;
}
else {
print "Err";

}
xslt_free($xh);

?>
xml文件
===========================================================
<?xml version="1.0" encoding="GB2312"?>
<?xml-stylesheet type="text/xsl" href="navigator.xsl" ?>
<Navigation>

<Navigator ID="1" AncestorID="1" Layer="0" Title="花園首頁" Childs="0" Url="default.asp&amp" Image="images/dc.gif"/>
<Navigator ID="2" AncestorID="2" Layer="0" Title="我的花園" Childs="4" Url="#" Image="default"/>
<Navigator ID="3" AncestorID="2" Layer="1" Title="收藏夾" Childs="4" Url="#" Image="default"/>
<Navigator ID="21" AncestorID="3" Layer="2" Title="我管理的花壇" Childs="0" Url="mybbs.asp?cat=g" Image="images/dc-new.gif"/>
<Navigator ID="22" AncestorID="3" Layer="2" Title="我種下的種子" Childs="0" Url="mybbs.asp?cat=t" Image="images/dc-new.gif"/>
<Navigator ID="23" AncestorID="3" Layer="2" Title="我喜歡的花園" Childs="0" Url="myfavorite.asp?cat=g&s=test" Image="images/dc-new.gif"/>
<Navigator ID="24" AncestorID="3" Layer="2" Title="我收藏的文章" Childs="0" Url="myfavorite.asp?cat=t" Image="images/dc-new.gif"/>
<Navigator ID="4" AncestorID="2" Layer="1" Title="個人工具箱" Childs="2" Url="#" Image="default"/>
<Navigator ID="25" AncestorID="4" Layer="2" Title="配置和管理" Childs="0" Url="personal.asp" Image="images/dc-config.gif"/>
<Navigator ID="26" AncestorID="4" Layer="2" Title="花瓣兌換點" Childs="0" Url="apetal.asp" Image="images/dc-config.gif"/>
<Navigator ID="27" AncestorID="2" Layer="1" Title="我的日記本" Childs="0" Url="mydiary.asp" Image="images/dc-diary.gif"/>
<Navigator ID="6" AncestorID="2" Layer="1" Title="好友和短訊" Childs="0" Url="myfriend.asp" Image="images/dc-friends.gif"/>
<Navigator ID="7" AncestorID="7" Layer="0" Title="計算機技術(shù)" Childs="2" Url="#" Image="default"/>
<Navigator ID="8" AncestorID="7" Layer="1" Title="DHTML,JScript" Childs="0" Url="bbsgroup.asp" Image="images/dc.gif"/>
<Navigator ID="9" AncestorID="7" Layer="1" Title=".NET,ASP+探討" Childs="0" Url="bbsgroup.asp" Image="images/dc.gif"/>
<Navigator ID="10" AncestorID="7" Layer="1" Title="ASP互助" Childs="0" Url="bbsgroup.asp" Image="images/dc.gif"/>
<Navigator ID="11" AncestorID="11" Layer="0" Title="箐箐校園" Childs="2" Url="#" Image="default"/>
<Navigator ID="12" AncestorID="11" Layer="1" Title="南京大學(xué)" Childs="0" Url="bbsgroup.asp" Image="images/dc.gif"/>
<Navigator ID="13" AncestorID="11" Layer="1" Title="東南大學(xué)" Childs="0" Url="bbsgroup.asp" Image="images/dc.gif"/>
<Navigator ID="14" AncestorID="14" Layer="0" Title="花園·有個廣場" Childs="2" Url="#" Image="default"/>
<Navigator ID="15" AncestorID="14" Layer="1" Title="意見箱" Childs="0" Url="bbsgroup.asp" Image="images/dc.gif"/>
<Navigator ID="16" AncestorID="14" Layer="1" Title="花園·人物故事" Childs="0" Url="bbsgroup.asp" Image="images/dc.gif"/>
<Navigator ID="17" AncestorID="17" Layer="0" Title="園丁辦公室" Childs="0" Url="bbsgroup.asp" Image="images/dc-key.gif"/>
<Navigator ID="18" AncestorID="18" Layer="0" Title="青青芳草地" Childs="0" Url="bbsgroup.asp" Image="images/dc.gif"/>
<Navigator ID="19" AncestorID="19" Layer="0" Title="統(tǒng)計信息" Childs="0" Url="viewlog.asp" Image="images/dc-chart.gif"/>
<Navigator ID="20" AncestorID="20" Layer="0" Title="ActiveCard" Childs="0" Url="activecard?fromgarden" Image="images/dc-card.gif"/>
</Navigation>


XSLT文件

============================================================
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method ="html" version="1.0" encoding="GB2312" indent="yes"/>
<xsl:template match="/">
<HTML>
<HEAD>
<TITLE>XSLT樹形導(dǎo)航欄</TITLE>
<LINK rel="stylesheet" type="text/css" href="navigator.css"/>
<SCRIPT src="toggle.js"></SCRIPT>
</HEAD>
<BODY>

<DIV >
<TABLE>
<TR>
<TD><DIV noWrap="true" STYLE="padding-left:0em;">有座花園分類目錄</DIV></TD>
</TR>
<xsl:for-each select="Navigation/Navigator">
<TR>
<xsl:attribute name="TITLE"><xsl:value-of select="@Title" /></xsl:attribute>
<xsl:attribute name="Class">Navigator<xsl:if test="@Layer[.>0]">-Hidden</xsl:if></xsl:attribute>
<xsl:attribute name="ID"><xsl:value-of select="@ID"/></xsl:attribute>
<xsl:attribute name="AncestorID"><xsl:value-of select="@AncestorID"/></xsl:attribute>
<xsl:attribute name="Depth"><xsl:value-of select="@Layer"/></xsl:attribute>
<xsl:if test="@Childs[.>0]">
<xsl:attribute name="Expanded">no</xsl:attribute>
</xsl:if>
<TD STYLE="cursor:hand">
<DIV noWrap="true"><xsl:attribute name="STYLE">padding-left:<xsl:value-of select="@Layer"/>em;</xsl:attribute>
<xsl:choose>
<xsl:when test="@Childs[.>0]"><IMG src=http://cfan.net.cn/info/"images/bs.gif"><xsl:attribute name="onclick">toggle('<xsl:value-of select="@ID" />')</xsl:attribute></IMG></xsl:when>
<xsl:otherwise><IMG><xsl:attribute name="src"><xsl:value-of select="@Image" /></xsl:attribute></IMG></xsl:otherwise>
</xsl:choose>
<A><xsl:if test="@Childs[.>0]"><xsl:attribute name="onclick">toggle('<xsl:value-of select="@ID" />')</xsl:attribute></xsl:if><xsl:attribute name="href"><xsl:value-of select="@Url" /></xsl:attribute><xsl:value-of select="@Title" /></A></DIV></TD>
</TR>
</xsl:for-each>
</TABLE>
</DIV>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>