Power by DMForum.NET!
RSS | ATOM | WAP
DMForum.NET 官方支持讨论区 > 技术区 > XML应用

浏览主题:???????????????????????????????????.????????????

主题:???????????????????????????????????.????????????
自在的尘
普通会员
5级
等级:侠之大者
发帖:940
金钱:1205
经验:3319
性别:帅哥
状态:离线
注册:2006-8-8 16:09:00
XML+XSLT无级分类的初步实现  
[ 2006-8-31 14:08:00 ]
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>
devms
管理员
8级
等级:黄金骑士
发帖:3934
金钱:4064
经验:25679
积分:2
性别:帅哥
状态:离线
注册:2006-7-29 23:37:00
RE:???????????????????????????????????.????????????  
[ 2006-8-31 20:56:00 ]
这叫无级分类,我倒,你不如别搞
自在的尘
普通会员
5级
等级:侠之大者
发帖:940
金钱:1205
经验:3319
性别:帅哥
状态:离线
注册:2006-8-8 16:09:00
啊,,,  
[ 2006-8-31 21:15:00 ]
DLL,,你认为怎么样的?
用XML做数据源?
VIP用户
普通会员
1级
等级:新手上路
发帖:7
金钱:10
经验:756
性别:保密
状态:离线
注册:2006-8-4 8:49:00
XSL 标准  
[ 2006-9-1 14:05:00 ]
http://www.w3.org/1999/XSL/Transform
http://www.w3.org/TR/WD-xsl

有什么不同,看这两个网址就知道了

最后一次由 VIP用户 在 2006-9-1 14:07:36 编辑
devms
管理员
8级
等级:黄金骑士
发帖:3934
金钱:4064
经验:25679
积分:2
性别:帅哥
状态:离线
注册:2006-7-29 23:37:00
RE:???????????????????????????????????.????????????  
[ 2006-9-1 14:05:00 ]
看错了。。
自在的尘
普通会员
5级
等级:侠之大者
发帖:940
金钱:1205
经验:3319
性别:帅哥
状态:离线
注册:2006-8-8 16:09:00
这,  
[ 2006-9-4 14:50:00 ]
我偷懒,没完成,结果月亮帮偶弄完了。

<?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>
fcuandy
(手中无剑心中亦无)
论坛版主
3级
等级:讨逆将军
发帖:104
金钱:230
经验:1424
性别:保密
状态:离线
注册:2006-8-3 14:11:00
RE:???????????????????????????????????.????????????  
[ 2006-10-27 11:35:00 ]
又帮你改进了一下.
含子节点的在前面增加了+.

<?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]) &gt; 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>
fcuandy
(手中无剑心中亦无)
论坛版主
3级
等级:讨逆将军
发帖:104
金钱:230
经验:1424
性别:保密
状态:离线
注册:2006-8-3 14:11:00
RE:???????????????????????????????????.????????????  
[ 2006-10-27 16:16:00 ]
span那句再改进一下

<span style="cursor:hand" onclick="this.innerHTML=='+'?this.innerHTML='-':this.innerHTML='+';">+</span>
李昌镐二世
(道道道)
论坛版主
6级
等级:后将军
发帖:244
金钱:1745
经验:11295
性别:帅哥
状态:离线
注册:2006-8-5 18:03:00
RE:???????????????????????????????????.????????????  
[ 2006-10-30 18:50:00 ]
不懂XML,一点也不懂
自在的尘
普通会员
5级
等级:侠之大者
发帖:940
金钱:1205
经验:3319
性别:帅哥
状态:离线
注册:2006-8-8 16:09:00
RE:???????????????????????????????????.????????????  
[ 2006-10-31 9:05:00 ]
把肥羊的继续完善了下。

<?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]) &gt; 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>

回到顶部
Powered by DMForum.NET  1.4 Beta . URIMAP enabled. DEBUG enabled.
Copyright © 2003-2006 Devms.Com. All rights reserved.