-- 作者:xjyanxml
-- 发布时间:11/24/2004 8:52:00 AM
-- xml+xsl树,带checkbox的问题
tree.xml <?xml version="1.0" encoding="GB2312"?> <?xml-stylesheet type='text/xsl' href='tree.xsl'?> <TreeView> <Tree Text="根节点" id="0001"> <Tree Text="1.1" id="0002" Expanded="true"> <Tree Text="1.1.1" id="0003"> <Tree Text="1.1.1.1" id="0004"> <Tree Text="1.1.1.1.1" id="0004" /> <Tree Text="1.1.1.1.2" id="0005"/> </Tree> <Tree Text="1.1.1.2" id="0006"/> </Tree> <Tree Text="1.1.2" id="0007"/> </Tree> <Tree Text="1.2" id="0008"> <Tree Text="1.2.1" id="0009"/> <Tree Text="1.2.2" id="0010"/> </Tree> </Tree> </TreeView> ============================================= tree.xsl <?xml version="1.0" encoding="gb2312"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"> <xsl:template match="/"> <HTML> <HEAD> <script> <xsl:comment> <![CDATA[ var CurrentNode = null; var iconLeaf = "<span class='clsLeaf'>.</span>"; var iconExpand = "<span class='clsExpand'>-</span>"; var iconCollapse = "<span class='clsCollapse'>+</span>"; function Expand(obj) { var div = null; var img = obj; if(obj.tagName != 'SPAN' || obj.className!='clsSpace') return (false); obj = obj.parentElement; var childRen=obj.children; for (var i=0;i < childRen.length;i++) { if(childRen[i].tagName == 'DIV'){ div = childRen[i]; break; } } if(div == null) return (false); if(obj.Expanded.toLowerCase()=='true') { if(img!=null) img.innerHTML = iconCollapse; obj.Expanded='false'; div.className='hide'; } else { if(img!=null) img.innerHTML = iconExpand; obj.Expanded='true'; div.className='shown' } } function MouseOver(obj) { obj.className = "clsMouseOver"; } function MouseOut(obj) { if(!obj.Checked) obj.className = "clsLabel"; else obj.className = "clsCurrentHasFocus"; } /* function:检验checkbox中的属性 time: author:zht */ function check_choose(checkobj) { if (checkobj.checked==true) { checkobj.checked=false; } else { checkobj.checked=true; } } function MouseDown(obj) { obj.className = "clsMouseDown"; } function MouseUp(obj) { MouseOut(obj); } function Click(obj) { alert(obj.outerHTML); //if(!obj.Checked) //{ //if(CurrentNode != null) //{ //CurrentNode.Checked = false; //MouseOut(CurrentNode); //} //obj.Checked = true; //CurrentNode = obj; //} //else //obj.Checked = false; //check_choose(obj.children[0]) //MouseOut(obj); } ]]> </xsl:comment> </script> <style> <![CDATA[ BODY { cursor:default; font-size:9pt; background-color:#F1F1F1; } span { padding:2px 3px; position:relative; display:inline; top:-2px; height:17px; border: solid 1px #f1f1f1; } span.clsLabel { } SPAN.clsSpace { font-family:verdana; position:relative; padding:3px 2px; top:0px; width:17px; margin:0px; cursor:hand; overflow:hidden; } span.clsSpace span { position:relative; width:11px; height:11px; border:solid 1px black; background-color:#ffffff; } SPAN.clsCollapse { line-height:6px; font-size:9px; overflow:hidden; padding:1px; } SPAN.clsExpand { padding-left:1px; overflow:hidden; line-height:3px; font-size:13px; padding-top:3px; } SPAN.clsLeaf { overflow:visible; font-size:9px; line-height:3px; padding: 1px 0px 0px 3px; } SPAN.clsMouseOver { background-color:#CCCCCC; border:1px solid #999999; } SPAN.clsMouseDown { background-color:#999999; border:1px solid #999999; } SPAN.clsCurrentHasFocus { background-color:#FFFFFF; border:1px solid #999999; } SPAN.clsCurrentNoFocus { background-color:#F1F1F1; border:1px solid #999999; } A { color:black; text-decoration:none; } span.clsUnavailable { height:0px; padding:0px; top:0px; border:none; color:#888888; } .hide { display:none; } .shown { display:block; margin-left:15px; } .deeptree IMG { position:relative; cursor:hand; top:-2px; margin:0px; padding:0px; } .treelabel { font-family:verdana; font-size:70.5%; color:white; } ]]> </style> <TITLE></TITLE> </HEAD> <BODY> <xsl:apply-templates select="/TreeView/Tree"/> </BODY> </HTML> </xsl:template> <xsl:template match="Tree"> <div class="clsItem" type="parent"> <xsl:if expr="this.hasChildNodes"> <xsl:choose> <xsl:when test="@Expanded"> <xsl:attribute name="Expanded"> <xsl:value-of select="@Expanded"/> </xsl:attribute> </xsl:when> <xsl:otherwise><xsl:attribute name="Expanded">false</xsl:attribute></xsl:otherwise> </xsl:choose> </xsl:if> <span> <xsl:if expr="this.hasChildNodes"> <xsl:attribute name="onclick">Expand(this)</xsl:attribute> </xsl:if> <xsl:attribute name="Class">clsSpace</xsl:attribute> <xsl:choose> <xsl:when expr="this.hasChildNodes"> <xsl:choose> <xsl:when test="@Expanded"> <xsl:choose> <xsl:when test="@Expanded[.='true']"> <span class='clsExpand'>-</span> </xsl:when> <xsl:otherwise><span class='clsCollapse'>+</span></xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise><span class='clsCollapse'>+</span></xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise><span class='clsLeaf'>.</span></xsl:otherwise> </xsl:choose> </span> <span class='clsLabel' onmouseover="MouseOver(this)" onmouseout="MouseOut(this)" onmousedown="MouseDown(this)" onmouseup="MouseUp(this)"> <input type="checkbox" name="ck" value="{@id}" onclick="Click(this)"></input> <xsl:attribute name="title"><xsl:value-of select="@id" /></xsl:attribute> <xsl:choose> <xsl:when test="@URL"> <a> <xsl:choose> <xsl:when test="@Target"> <xsl:attribute name="target"><xsl:value-of select="@Target" /></xsl:attribute> </xsl:when> <xsl:otherwise> <xsl:attribute name="target">_blank</xsl:attribute> </xsl:otherwise> </xsl:choose> <xsl:attribute name="Href"> <xsl:value-of select="@URL"/> </xsl:attribute> <xsl:value-of select="@id"/> </a> </xsl:when> <xsl:otherwise><xsl:value-of select="@Text"/></xsl:otherwise> </xsl:choose> </span> <xsl:if expr="this.hasChildNodes"> <div> <xsl:choose> <xsl:when test="@Expanded"> <xsl:choose> <xsl:when test="@Expanded[.='true']"> <xsl:attribute name="class">shown</xsl:attribute> </xsl:when> <xsl:otherwise> <xsl:attribute name="class">hide</xsl:attribute> </xsl:otherwise> </xsl:choose> </xsl:when> <xsl:otherwise> <xsl:attribute name="class">hide</xsl:attribute> </xsl:otherwise> </xsl:choose> <xsl:choose> <xsl:when test="@Expanded"> <xsl:attribute name="Expanded"> <xsl:value-of select="@Expanded"/> </xsl:attribute> </xsl:when> <xsl:otherwise><xsl:attribute name="Expanded">false</xsl:attribute></xsl:otherwise> </xsl:choose> <xsl:apply-templates select="Tree"></xsl:apply-templates> </div> </xsl:if> </div> </xsl:template> </xsl:stylesheet> ============================= 我的问题是如何生成checkbox的value,如:每个树节点对应xml的node的id (0001);因为我要保存他到数据库中
|