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

浏览主题:???nj?.传媥igm?tbtbnj.国?????配音?京配???gc?h传io???gm.传h传京配?

主题:???nj?.传媥igm?tbtbnj.国?????配音?京配???gc?h传io???gm.传h传京配?
coderlee
普通会员
1级
等级:新手上路
发帖:40
金钱:430
经验:2437
性别:保密
状态:离线
注册:2006-12-11 15:22:00
XML(树结构)+XSLT无限分类的初步实现  
[ 2007-1-11 13:57:07 ]
嘿嘿  先BS一下自己    太笨了  所以不想用关系模型存储树结构
所以就写成树结构了

xml 程序代码
 1 <?xml version="1.0" encoding="gb2312"?>
 2 <?xml-stylesheet type="text/xsl" href="../../xslt/catalog/article.catalog.xsl"?>
 3 <Catalogs>
 4     <Catalog Catalog_ID="1" Catalog_Name="menu1" Catalog_Depth="0">
 5         <Catalog Catalog_ID="2" Catalog_Name="menu11" Catalog_Depth="1">
 6             <Catalog Catalog_ID="5" Catalog_Name="menu111" Catalog_Depth="2"></Catalog>
 7         </Catalog>
 8         <Catalog Catalog_ID="3" Catalog_Name="menu12" Catalog_Depth="1"></Catalog>
 9     </Catalog>
10     <Catalog Catalog_ID="4" Catalog_Name="menu2" Catalog_Depth="0">
11     </Catalog>
12 </Catalogs>



下面是catalog.selectcontrol.xsl

xml 程序代码
 1 <?xml version="1.0" encoding="gb2312"?>
 2 <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" >
 3 <xsl:template match="/">
 4 <xsl:for-each select="//Catalog">
 5 <option>
 6 <!-- 这里要输出 @Catalog_Depth 个横线啊 -->
 7 <xsl:attribute name="value">
 8     <xsl:value-of select="@Catalog_ID"/>
 9 </xsl:attribute>
10 <xsl:value-of select="@Catalog_Name"/>
11 </option>
12 </xsl:for-each>
13 </xsl:template>
14 </xsl:stylesheet>


待解决的问题是如何循环输出  @Catalog_Depth  个横线   

麻烦路过的给想想办法
devms
管理员
8级
等级:黄金骑士
发帖:3934
金钱:4064
经验:25679
积分:2
性别:帅哥
状态:离线
注册:2006-7-29 23:37:00
RE:???nj?.传媥igm?tbtbnj.国?????配音?京配???gc?h传io???gm.传h传京配?  
[ 2007-1-11 15:21:40 ]
看看下面的代码能不能运行
xml 程序代码
 1 <?xml version="1.0" encoding="gb2312"?>
 2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
 3 <xsl:output method="html" version="4.0" encoding="gb2312" indent="yes"/>
 4 <xsl:template name="nodelist">
 5 <xsl:param name="depth"></xsl:param>
 6 <xsl:param name="nodes"></xsl:param>
 7     <xsl:for-each select="$nodes">
 8         <option>
 9             <xsl:attribute name="value"><xsl:value-of select="@Catalog_ID"/></xsl:attribute>
10             <xsl:value-of select="$depth"/>
11             <xsl:value-of select="@Catalog_Name"/>
12         </option>
13         <xsl:call-template name="nodelist"><xsl:with-param name="nodes" select="./Catalog"/><xsl:with-param name="depth"><xsl:value-of select="$depth"/>--</xsl:with-param></xsl:call-template>
14     </xsl:for-each>
15 </xsl:template>
16 
17 <xsl:template match="/">
18     <select>
19         <xsl:call-template name="nodelist"><xsl:with-param name="nodes" select="/Catalogs/Catalog"/><xsl:with-param name="depth"></xsl:with-param></xsl:call-template>
20     </select>
21 </xsl:template>
22 
23 </xsl:stylesheet>
编辑标志
本帖最后由[devms]在  2007-1-11  15:52:19  编辑
coderlee
普通会员
1级
等级:新手上路
发帖:40
金钱:430
经验:2437
性别:保密
状态:离线
注册:2006-12-11 15:22:00
看我的  
[ 2007-1-11 16:33:08 ]
xml 程序代码
 1 <?xml version="1.0" encoding="gb2312"?>
 2 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
 3 <xsl:output method="html" version="4.0" encoding="gb2312" indent="yes"/>
 4 
 5 <xsl:template name="show">
 6     <xsl:param name="For_ID"/>
 7     <xsl:for-each select="//Catalog[@Catalog_Depth=$For_ID]">
 8         <option>
 9             <xsl:attribute name="value">
10                 <xsl:value-of select="@Catalog_ID"/>
11             </xsl:attribute>
12             <xsl:value-of select="@Catalog_Name"/>
13         </option>
14         <xsl:if test="./Catalog">
15         <xsl:call-template name="show"><xsl:with-param name="For_ID" select="@Catalog_Depth+1" /></xsl:call-template>
16         </xsl:if>
17     </xsl:for-each>
18 </xsl:template>
19 
20 <xsl:template match="/">
21     <select>
22         <xsl:call-template name="show">
23             <xsl:with-param name="For_ID" select="0" />
24         </xsl:call-template>
25     </select>
26 </xsl:template>
27 </xsl:stylesheet>
coderlee
普通会员
1级
等级:新手上路
发帖:40
金钱:430
经验:2437
性别:保密
状态:离线
注册:2006-12-11 15:22:00
RE:???nj?.传媥igm?tbtbnj.国?????配音?京配???gc?h传io???gm.传h传京配?  
[ 2007-1-11 16:33:55 ]

我去弹棉花了。

编辑标志
本帖最后由[coderlee]在 2007-6-27 16:39:26 编辑
coderlee
普通会员
1级
等级:新手上路
发帖:40
金钱:430
经验:2437
性别:保密
状态:离线
注册:2006-12-11 15:22:00
RE:???nj?.传媥igm?tbtbnj.国?????配音?京配???gc?h传io???gm.传h传京配?  
[ 2007-3-7 15:31:21 ]

待解决的问题是如何循环输出 @Catalog_Depth 个横线

麻烦路过的给想想办法

re:

我刚才写了一个xsl的for循环 用xsl:for-each的递归实现的

xml 程序代码
 1 
 2 <xsl:template name="showChar">
 3 <xsl:param name="char"></xsl:param>
 4 <xsl:param name="count"></xsl:param>
 5 
 6 <xsl:if test="$count > 0">
 7 <xsl:value-of select="$char"/> 
 8 <xsl:call-template name="showChar">
 9 <xsl:with-param name="count" select="count-1"></xsl:with-param>
10 </xsl:call-template>
11 </xsl:if>
12 </xsl:template>
13 

编辑标志
本帖最后由[coderlee]在 2007-3-7 15:33:58 编辑

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