使用时需要加载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&"
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="计算机技术\" 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="南京大学" Childs="0" Url="bbsgroup.asp"
Image="images/dc.gif"/>
<Navigator ID="13" AncestorID="11"
Layer="1" Title="东南大学" 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="统计信息" 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树形导航栏</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="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>