以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XML源码及示例(仅原创和转载) 』  (http://bbs.xml.org.cn/list.asp?boardid=32)
----  偶是菜鸟,我想在一个由xml生成的树形目录上添加checkbox,怎么添加呀?  (http://bbs.xml.org.cn/dispbbs.asp?boardid=32&rootid=&id=6207)


--  作者:ecard
--  发布时间:3/25/2004 4:10:00 PM

--  偶是菜鸟,我想在一个由xml生成的树形目录上添加checkbox,怎么添加呀?
偶是菜鸟,我想在一个由xml生成的树形目录上添加checkbox,怎么添加呀?
这个东西是网上下的一个示例,我想在每个接点上加一个选择框checkbox,怎么加?
<a href="http://www.vckbase.com/code/downcode.asp?id=1629">下载例子代码</a>
以下是tree.xml的原文:
<?xml version="1.0" encoding="gb2312"?>
<tree>
  <entity id="e1">
    <description>在线杂志</description>
    <image>images/book.gif</image>
    <imageOpen>images/bookOpen.gif</imageOpen>
<checkbox>e1</checkbox>
    <contents>
      <entity id="e2">
        <description>第十二期</description>
        <image>images/book.gif</image>
        <imageOpen>images/bookOpen.gif</imageOpen>
        <onClick></onClick>
        <contents>
          <entity id="e3">
            <description>组件对象模型</description>
            <image>images/book.gif</image>
            <imageOpen>images/bookOpen.gif</imageOpen>
            <onClick></onClick>
            <contents>
              <entity id="e4">
                <description>OLE 编程</description>
                <image>images/paper.gif</image>
                <imageOpen>images/paper.gif</imageOpen>
                <onClick></onClick>
                <contents/>
              </entity>
              <entity id="e5">
                <description>ATL编程</description>
                <image>images/book.gif</image>
                <imageOpen>images/bookOpen.gif</imageOpen>
                <onClick></onClick>
           <contents>
             <entity id="e51">
               <description>OLE 编程</description>
               <image>images/paper.gif</image>
               <imageOpen>images/paper.gif</imageOpen>
               <onClick></onClick>
               <contents/>
             </entity>
             <entity id="e52">
               <description>ATL编程</description>
               <image>images/paper.gif</image>
               <imageOpen>images/paper.gif</imageOpen>
               <onClick></onClick>
               <contents/>
             </entity>
           </contents>
              </entity>
            </contents>
          </entity>
          <entity id="e3">
            <description>dotNet框架</description>
            <image>images/book.gif</image>
            <imageOpen>images/bookOpen.gif</imageOpen>
            <onClick></onClick>
            <contents>
              <entity id="e4">
                <description>C# 编程</description>
                <image>images/paper.gif</image>
                <imageOpen>images/paper.gif</imageOpen>
                <onClick></onClick>
                <contents/>
              </entity>
              <entity id="e5">
                <description>数据库编程</description>
                <image>images/paper.gif</image>
                <imageOpen>images/paper.gif</imageOpen>
                <onClick></onClick>
                <contents/>
              </entity>
            </contents>
          </entity>
        </contents>
      </entity>
      <entity id="e2">
        <description>第十三期</description>
        <image>images/book.gif</image>
        <imageOpen>images/bookOpen.gif</imageOpen>
        <onClick></onClick>
        <contents>
          <entity id="e3">
            <description>组件对象模型</description>
            <image>images/book.gif</image>
            <imageOpen>images/bookOpen.gif</imageOpen>
            <onClick></onClick>
            <contents>
              <entity id="e4">
                <description>OLE 编程</description>
                <image>images/paper.gif</image>
                <imageOpen>images/paper.gif</imageOpen>
                <onClick>www.vckbase.com/index.html</onClick>
                <contents/>
              </entity>
              <entity id="e5">
                <description>ATL编程</description>
                <image>images/paper.gif</image>
                <imageOpen>images/paper.gif</imageOpen>
                <onClick>www.vckbase.com/index.html</onClick>
                <contents/>
              </entity>
            </contents>
          </entity>
          <entity id="e3">
            <description>dotNet框架</description>
            <image>images/book.gif</image>
            <imageOpen>images/bookOpen.gif</imageOpen>
            <onClick></onClick>
            <contents>
              <entity id="e4">
                <description>C# 编程</description>
                <image>images/paper.gif</image>
                <imageOpen>images/paper.gif</imageOpen>
                <onClick></onClick>
                <contents/>
              </entity>
              <entity id="e5">
                <description>数据库编程</description>
                <image>images/paper.gif</image>
                <imageOpen>images/paper.gif</imageOpen>
                <onClick></onClick>
                <contents/>
              </entity>
            </contents>
          </entity>
        </contents>
      </entity>
    </contents>
  </entity>
</tree>
tree.xsl文件的内容如下:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" language="javascript">
<xsl:template match="tree">
  <xsl:apply-templates select="entity"/>
</xsl:template>

<xsl:template match="entity">
  <div onclick="window.event.cancelBubble = true;clickOnEntity(this);" onselectstart="return false" ondragstart="return false">
  <xsl:attribute name="image"><xsl:value-of select="image"/></xsl:attribute>
  <xsl:attribute name="imageOpen"><xsl:value-of select="imageOpen"/></xsl:attribute>
  <xsl:attribute name="open">false</xsl:attribute>
  <xsl:attribute name="id">f<xsl:value-of select="@id"/></xsl:attribute>
  <xsl:attribute name="open">false</xsl:attribute>
  <xsl:attribute name="STYLE">
    padding-left: 20px;
    cursor: hand;
    <xsl:if expr="depth(this) > 2">
      display: none;
    </xsl:if>
  </xsl:attribute>
    <table border="0" cellspacing="0" cellpadding="0">
      <tr>
        <td valign="middle">
          <img border="0" id="image">
            <xsl:attribute name="SRC">
              <xsl:value-of select="image"/>
            </xsl:attribute>
          </img>
        </td>
        <td valign="middle" nowrap="true">
        <xsl:attribute name="STYLE">
          padding-left: 7px;
          font-family: Verdana;
          font-size: 11px;
          font-color: black;
        </xsl:attribute>
        <xsl:value-of select="description"/></td>
      </tr>
    </table>
  <xsl:apply-templates select="contents/entity"/>
  </div>
</xsl:template>

</xsl:stylesheet>
tree.js的内容:
function initialize() {
  var xmlDoc
  var xslDoc

  xmlDoc = new ActiveXObject(''''Microsoft.XMLDOM'''')
  xmlDoc.async = false;

  xslDoc = new ActiveXObject(''''Microsoft.XMLDOM'''')
  xslDoc.async = false;

  xmlDoc.load("tree/tree.xml")
  xslDoc.load("tree/tree.xsl")

  folderTree.innerHTML = xmlDoc.documentElement.transformNode(xslDoc)
}

function clickOnEntity(entity) {
  if(entity.open == "false") {
    expand(entity, true)
  }
  else {
    collapse(entity)
  }
  window.event.cancelBubble = true
}

function expand(entity) {
  var oImage

  oImage = entity.childNodes(0).all["image"]
  oImage.src = entity.imageOpen
  for(i=0; i < entity.childNodes.length; i++) {
    if(entity.childNodes(i).tagName == "DIV") {
      entity.childNodes(i).style.display = "block"
    }
  }
  entity.open = "true"
}

function collapse(entity) {
  var oImage
  var i

  oImage = entity.childNodes(0).all["image"]
  oImage.src = entity.image

  // 收缩和隐藏字节点
  for(i=0; i < entity.childNodes.length; i++) {
      if(entity.childNodes(i).tagName == "DIV") {
        if(entity.id != "folderTree") entity.childNodes(i).style.display = "none"
        collapse(entity.childNodes(i))
      }
    }
  entity.open = "false"
}

function expandAll(entity) {
  var oImage
  var i

  expand(entity, false)

  // 展开子节点
  for(i=0; i < entity.childNodes.length; i++) {
    if(entity.childNodes(i).tagName == "DIV") {
      expandAll(entity.childNodes(i))
    }
  }
}      

麻烦大家了,江湖救急呀,我等着用这个来显示一棵很大很大的树呢。


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
12,753.910ms