浏览主题:???????????????????????????????????.????????????
主题:???????????????????????????????????.????????????
|
XML+XSLT无级分类,弄成这样了,差不多了,就只有缩进的问题没解决了,不知道Xpath能解决不。
实在不行,用JS控制就是。 人懒,先闪,这两天有空再把这全弄完整 另外还有一点搞不清 <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> 这两个东西有什么样的区别呢????? XML文件 <?xml-stylesheet type="text/xsl" href="Tree.xsl"?> <?xml version="1.0" encoding="GB2312"?> <table> <record> <id>1</id> <name>Linux</name> <parent>0</parent> </record> <record> <id>3</id> <name>Gentoo</name> <parent>1</parent> </record> <record> <id>4</id> <name>Slackeare</name> <parent>1</parent> </record> <record> <id>5</id> <name>Slax</name> <parent>4</parent> </record> <record> <id>6</id> <name>Slackintoch</name> <parent>4</parent> </record> <record> <id>9</id> <name>Slax 5.0</name> <parent>5</parent> </record> <record> <id>10</id> <name>Slax Kill Bill</name> <parent>5</parent> </record> </table> XSL文件 <?xml version="1.0" encoding="GB2312"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <xsl:apply-templates select="//record[parent=0]"/> </html> </xsl:template> <xsl:template match="//record"> <xsl:param name="id" select="id"/> <xsl:value-of select="name"/>__<xsl:value-of select="id"/>__<xsl:value-of select="parent"/> <div> <xsl:apply-templates select="//record[parent=$id]"/> </div> </xsl:template> </xsl:transform> 这是执行后的结果 <html> Linux__1__0 <div> Gentoo__3__1 <div></div> Slackeare__4__1 <div> Slax__5__4 <div> Slax 5.0__9__5 <div></div> Slax Kill Bill__10__5<div></div> </div> Slackintoch__6__4 <div></div> </div> </div> </html> |
|
这叫无级分类,我倒,你不如别搞
|
|
DLL,,你认为怎么样的?
用XML做数据源? |
|
http://www.w3.org/1999/XSL/Transform
http://www.w3.org/TR/WD-xsl 有什么不同,看这两个网址就知道了 最后一次由 VIP用户 在 2006-9-1 14:07:36 编辑 |
|
看错了。。
|
|
我偷懒,没完成,结果月亮帮偶弄完了。
<?xml version="1.0" encoding="utf-8"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <xsl:apply-templates select="//record[parent=0]"/> </html> </xsl:template> <xsl:template match="//record"> <xsl:param name="id" select="id"/> <div id="{$id}" onclick="s{$id}.style.display=='none'?s{$id}.style.display='block':s {$id}.style.display='none'"><xsl:value-of select="name"/>__<xsl:value-of select="id"/>__<xsl:value-of select="parent"/></div> <div id="s{$id}" style="display:none;margin-left:30px;color:#00{$id}{$id}{$id}{$id}"> <xsl:apply-templates select="//record[parent=$id]"/> </div> </xsl:template> </xsl:transform> |
|
又帮你改进了一下.
含子节点的在前面增加了+. <?xml version="1.0" encoding="utf-8"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <xsl:apply-templates select="//person[parent=0]"/> </html> </xsl:template> <xsl:template match="//person"> <xsl:param name="id" select="id"/> <div id="{$id}" onclick="s{$id}.style.display=='none'?s{$id}.style.display='block':s{$id}.style.display='none'"> <xsl:choose> <xsl:when test="count(//person[parent=$id]) > 0"> <span style="cursor:hand">+</span> </xsl:when> <xsl:otherwise>-</xsl:otherwise> </xsl:choose> <xsl:value-of select="name"/></div> <div id="s{$id}" style="display:none;margin-left:30px;"> <xsl:apply-templates select="//person[parent=$id]"/> </div> </xsl:template> </xsl:transform> |
|
span那句再改进一下
<span style="cursor:hand" onclick="this.innerHTML=='+'?this.innerHTML='-':this.innerHTML='+';">+</span> |
|
不懂XML,一点也不懂
|
|
把肥羊的继续完善了下。
<?xml version="1.0" encoding="utf-8"?> <xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <html> <xsl:apply-templates select="//record[parent=0]"/> </html> </xsl:template> <xsl:template match="//record"> <xsl:param name="id" select="id"/> <xsl:choose> <xsl:when test="count(//record[parent=$id]) > 0"> <div style="cursor:hand" onclick= "D{$id}.style.display=='none'?D{$id}.style.display='block':D{$id}.style.display='none'; S{$id}.innerHTML=='+ '?S{$id}.innerHTML='- ':S{$id}.innerHTML='+ '"> <span id="S{$id}" >+ </span> <xsl:value-of select="name"/> </div> </xsl:when> <xsl:otherwise>- <xsl:value-of select="name"/><br /></xsl:otherwise> </xsl:choose> <div id="D{$id}" style="display:none;margin-left:30px;"> <xsl:apply-templates select="//record[parent=$id]"/> </div> </xsl:template> </xsl:transform> |