我引用花園的TOC,一是讓大家能有個初步印象,等文章完成后, 把幾個文件C&P加上幾個圖片, 在IE5以上的機器上象打開一個html文件一樣打開navi.xml后,就會出現跟花園很類似的TOC了;二是希望大家根據它的層次結構來分析我的xml文件, 因為除頂層外, 我的層次安排和花園是一樣的。 我來解釋一下:Layer相同表示元素處在同一層次即兄弟關系, Childs的值表示該元素是否有子結點, 父子之間用AncestorID和ID聯系, 依次類推可以擴充至無限次深。 在xsl文件中根據Layer的值用padding-left屬性來實現樹形,根據Layer的值用display:none或block來實現折疊。 原理即此, 好,來看看這個關鍵的Navigator.xsl: <?xml version="1.0" encoding="gb2312" ?> <HTML> <HEAD> <TITLE>XSLT樹形導航欄</TITLE> <LINK rel="stylesheet" type="text/css" href="navigator.css"/> <SCRIPT src="toggle.js"></SCRIPT> </HEAD> <BODY>
<DIV xmlns:xsl="http://www.w3.org/TR/WD-xsl" > <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://edu.chinaz.com/Get/Program/Xml/images/bs.gif"></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>
|