用Java实现可保存状态的数据库生成XML树,最后一个源码(12),新手高手都看看吧,也不枉我一片苦心啊!

发表于:2007-07-01来源:作者:点击数: 标签:
6.3.3.XSL源码 1.treefunc.xsl ?xml version=1.0 encoding=gb2312 ? xsl:stylesheet xmlns:xsl=http://www.w3.org/TR/WD-xsl xsl:template match=/ html head style #foldheader{cursor:hand ;list-style-image:url(/images/fold.gif);padding-left-width:-3}
6.3.3.XSL源码
1.treefunc.xsl
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<html>
<head>
<style>
#foldheader{cursor:hand ;list-style-image:url(/images/fold.gif);padding-left-width:-3}
#foldinglist{list-style-image:url(/images/list.gif);list-left-width:-3}
a:link{COLOR: #051679;TEXT-DECORATION: none}
a:visited{COLOR: #D91656;TEXT-DECORATION: none}
a:hover{COLOR: #clearcase/" target="_blank" >cc0000;TEXT-DECORATION: underline}
body{FONT-SIZE: 10pt;}
</style>
</head>

<SCRIPT for="window" event="onload">
<xsl:comment><![CDATA][
    var temp_str = @#thexmltreecookie@#;
    var fl_n = 0;
    temp_str = temp_str + "=";
    for (i=0;i<foldinglist.length;i++){
            temp_str=temp_str+"0:";
        }
        temp_str = temp_str.substring(0,temp_str.length-1);
        fl_n = temp_str.length -17 ;
        if ((document.cookie == @#@#)||(WM_readCookie(@#thexmltreecookie@#).length != fl_n)){
            document.cookie = temp_str;
        }
        else {
            var temp_s = WM_readCookie("thexmltreecookie").split(":");
            for (i=0;i<foldinglist.length;i++){
                if (temp_s][i] == 0){
                           var tb =0;
                           for (j=0;tb < 1;j++){
                              if (document.all[j] == foldinglist[i]){
                                    tb = 1;
                                    document.all[j-1].style.listStyleImage="url(/images/fold.gif)";
                              }
                           }
                           foldinglist[i].style.display="none";
                    }
                    else {
                           var tb =0;
                           for (j=0;tb < 1;j++){
                              if (document.all[j] == foldinglist[i]){
                                    tb = 1;
                                    document.all[j-1].style.listStyleImage="url(/images/open.gif)";
                              }
                           }
                           foldinglist[i].style.display="";
                    }
             }
          }
]]></xsl:comment>
</SCRIPT>


<script>

<xsl:comment><![CDATA][
    img1=new Image()
    img1.src="/images/fold.gif"
    img2=new Image()
    img2.src="/images/open.gif"

    function change(){
              if(!document.all)
                 return;
              var temp_ss =WM_readCookie("thexmltreecookie").split(":");
              var temp_s = @#thexmltreecookie@#;
              temp_s = temp_s + @#=@#;
              if (event.srcElement.id=="foldheader") {
                 var srcIndex = event.srcElement.sourceIndex;
                 var nested = document.all][srcIndex+1];
                 for (i=0;i<foldinglist.length;i++){
                        if (foldinglist[i] == nested){
                            var ClickId;
                            ClickId = "ClickId="+event.srcElement.no;
                            document.cookie =ClickId;
                            //alert(document.cookie);
                               if (temp_ss[i]==0){
                                  temp_ss[i]=1;
                               }
                               else {
                                 temp_ss[i]=0;
                               }
                        }
                 }
                 for (i=0;i<foldinglist.length;i++){
                        temp_s =temp_s+temp_ss[i]+@#:@#;
                 }
                 temp_s = temp_s.substring(0,temp_s.length-1);
                 document.cookie = temp_s;
                 //var ClickId;
                 //ClickId = "ClickId="+nested;
                 //document.cookie = ClickId;
                 //alert(document.cookie);
                 if (nested.style.display=="none") {
                        nested.style.display=@#@#
                        event.srcElement.style.listStyleImage="url(/images/open.gif)"
                 }
                 else {
                        nested.style.display="none"
                        event.srcElement.style.listStyleImage="url(/images/fold.gif)"
                 }
             top.topFrame.location.reload();
              }
       }
       document.onclick=change;
       
       function WM_readCookie(name){
              //如果没有cookie则返回false或者取得值并返回该值
             if(document.cookie == @#@#){
                   return false;
             }
             else {
                   return unescape(WM_getCookieValue(name));
             }  
       }
   
    function WM_getCookieValue(name){
              var firstChar,lastChar;
              var theBigCookie = document.cookie;
              firstChar = theBigCookie.indexOf(name);
              if (firstChar != -1){
                 firstChar += name.length + 1;
                 // Find the end of the value string (i.e. the next @#;@#).
                 lastChar = theBigCookie.indexOf(@#;@#, firstChar);
                 if(lastChar == -1) lastChar = theBigCookie.length;
                 // Return the value.
                 return theBigCookie.substring(firstChar, lastChar);
              }
              else {
                 // If there was no cookie, return false.
                 return false;
              }
       }
]]></xsl:comment>
</script>

<body>
<ul >
<xsl:apply-templates select="project/node"/>
</ul>
</body>
</html>
</xsl:template>
<xsl:template match="node">
  <xsl:for-each select=".[number(layer) $eq$ 0 ]">
      <xsl:if test=".[href $eq$ @#@#]">
       <xsl:element name ="li">
        <xsl:attribute name="id">foldheader</xsl:attribute>
        <xsl:attribute name="no"><xsl:value-of select="id"/></xsl:attribute>
        <xsl:value-of select="value"/>
       </xsl:element>
       <ul id="foldinglist" style="display:none" >
          <xsl:for-each select="./node[number(layer) $eq$ 1]">
           <xsl:if test=".[href $eq$ @#@#]">
             <xsl:element name ="li">
              <xsl:attribute name="id">foldheader</xsl:attribute>
              <xsl:attribute name="no"><xsl:value-of select="id"/></xsl:attribute>
              <xsl:value-of select="value"/>
             </xsl:element>
             <ul id="foldinglist" style="display:none" >
              <xsl:for-each select="./node[number(layer) $eq$ 2]">
                <xsl:if test=".[href $ne$ @#@#]">
                <li><xsl:element name ="a">
                <xsl:attribute name="HREF">
                <xsl:value-of select="href"/>
                </xsl:attribute>
                <xsl:attribute name="TARGET"><xsl:value-of select="target"/></xsl:attribute>
                <xsl:value-of select="value"/>
                </xsl:element></li>
                </xsl:if>
                <xsl:if test=".[href $eq$ @#@#]">
                <xsl:element name ="li">
                 <xsl:attribute name="id">foldheader</xsl:attribute>
                 <xsl:attribute name="no"><xsl:value-of select="id"/></xsl:attribute>
                 <xsl:value-of select="value"/>
                </xsl:element>
                <ul id="foldinglist" style="display:none" >
                <xsl:for-each select="./node[number(layer) $eq$ 3]">
                   <xsl:if test=".[href $ne$ @#@#]">
                     <li><xsl:element name ="a">
                      <xsl:attribute name="HREF">
                      <xsl:value-of select="href"/>
                      </xsl:attribute>
                      <xsl:attribute name="TARGET"><xsl:value-of select="target"/></xsl:attribute>
                      <xsl:value-of select="value"/>
                      </xsl:element></li>
                   </xsl:if>
                   <xsl:if test=".[href $eq$ @#@#]">
                     <xsl:element name ="li">
                      <xsl:attribute name="id">foldheader</xsl:attribute>
                      <xsl:attribute name="no"><xsl:value-of select="id"/></xsl:attribute>
                      <xsl:value-of select="value"/>
                     </xsl:element>
                     <ul id="foldinglist" style="display:none" >
                     <xsl:for-each select="./node[number(layer) $eq$ 4]">
                        <xsl:if test=".[href $ne$ @#@#]">
                        <li><xsl:element name ="a">
                        <xsl:attribute name="HREF">
                        <xsl:value-of select="href"/>
                        </xsl:attribute>
                        <xsl:attribute name="TARGET"><xsl:value-of select="target"/></xsl:attribute>
                        <xsl:value-of select="value"/>
                        </xsl:element></li>
                        </xsl:if>
                        <xsl:if test=".[href $eq$ @#@#]">
                        <xsl:element name ="li">
                         <xsl:attribute name="id">foldheader</xsl:attribute>
                         <xsl:attribute name="no"><xsl:value-of select="id"/></xsl:attribute>
                         <xsl:value-of select="value"/>
                        </xsl:element>
                        <ul id="foldinglist" style="display:none" >
                        <xsl:for-each select="./node[number(layer) $eq$ 5]">
                           <xsl:if test=".[href $ne$ @#@#]">
                           <li><xsl:element name ="a">
                            <xsl:attribute name="HREF">
                            <xsl:value-of select="href"/>
                            </xsl:attribute>
                            <xsl:attribute name="TARGET"><xsl:value-of select="target"/></xsl:attribute>
                            <xsl:value-of select="value"/>
                           </xsl:element></li>
                           </xsl:if>
                           <xsl:if test=".[href $eq$ @#@#]">
                           <xsl:element name ="li">
                            <xsl:attribute name="id">foldheader</xsl:attribute>
                            <xsl:attribute name="no"><xsl:value-of select="id"/></xsl:attribute>
                            <xsl:value-of select="value"/>
                           </xsl:element>
                           <ul id="foldinglist" style="display:none" >
                           <xsl:for-each select="./node[number(layer) $eq$ 6]">
                              <xsl:if test=".[href $ne$ @#@#]">
                              <li><xsl:element name ="a">
                               <xsl:attribute name="HREF">
                               <xsl:value-of select="href"/>
                               </xsl:attribute>
                               <xsl:attribute name="TARGET"><xsl:value-of select="target"/></xsl:attribute>
                               <xsl:value-of select="value"/>
                              </xsl:element></li>
                              </xsl:if>
                              <xsl:if test=".[href $eq$ @#@#]">
                              <xsl:element name ="li">
                               <xsl:attribute name="id">foldheader</xsl:attribute>
                               <xsl:attribute name="no"><xsl:value-of select="id"/></xsl:attribute>
                               <xsl:value-of select="value"/>
                              </xsl:element>
                              <ul id="foldinglist" style="display:none" >
                              <xsl:for-each select="./node[number(layer) $eq$ 7]">
                                 <xsl:if test=".[href $ne$ @#@#]">
                                 <li><xsl:element name ="a">
                                  <xsl:attribute name="HREF">
                                  <xsl:value-of select="href"/>
                                  </xsl:attribute>
                                  <xsl:attribute name="TARGET"><xsl:value-of select="target"/></xsl:attribute>
                                  <xsl:value-of select="value"/>
                                 </xsl:element></li>
                                 </xsl:if>
                                 <xsl:if test=".[href $eq$ @#@#]">
                                 <xsl:element name ="li">
                                  <xsl:attribute name="id">foldheader</xsl:attribute>
                                  <xsl:attribute name="no"><xsl:value-of select="id"/></xsl:attribute>
                                  <xsl:value-of select="value"/>
                                 </xsl:element>
                                 <ul id="foldinglist" style="display:none" >
                                 <xsl:for-each select="./node[number(layer) $eq$ 8]">
                                    <xsl:if test=".[href $ne$ @#@#]">
                                    <li><xsl:element name ="a">
                                     <xsl:attribute name="HREF">
                                     <xsl:value-of select="href"/>
                                     </xsl:attribute>
                                     <xsl:attribute name="TARGET"><xsl:value-of select="target"/></xsl:attribute>
                                     <xsl:value-of select="value"/>
                                    </xsl:element></li>
                                    </xsl:if>
                                 </xsl:for-each>
                                 </ul>
                                 </xsl:if>
                              </xsl:for-each>
                              </ul>
                              </xsl:if>
                           </xsl:for-each>
                           </ul>
                           </xsl:if>
                        </xsl:for-each>
                        </ul>
                        </xsl:if>
                     </xsl:for-each>
                     </ul>
                   </xsl:if>
                </xsl:for-each>
                </ul>
                </xsl:if>
              </xsl:for-each>
             </ul>
           </xsl:if>  
           <xsl:if test=".[href $ne$ @#@#]">
            <li><xsl:element name ="a">
            <xsl:attribute name="HREF">
            <xsl:value-of select="href"/>
            </xsl:attribute>
            <xsl:attribute name="TARGET"><xsl:value-of select="target"/></xsl:attribute>
            <xsl:value-of select="value"/>
            </xsl:element></li>
           </xsl:if>
          </xsl:for-each>
       </ul>
  </xsl:if>
  <xsl:if test=".[href $ne$ @#@#]">
     <li><xsl:element name ="a">
            <xsl:attribute name="HREF">
            <xsl:value-of select="href"/>
            </xsl:attribute>
            <xsl:attribute name="TARGET"><xsl:value-of select="target"/></xsl:attribute>
            <xsl:value-of select="value"/>
            </xsl:element>
     </li>
  </xsl:if>
  
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
  

原文转自:http://www.ltesting.net