xsl实战:通过xml生成功能菜单树

来源:互联网 发布:udp 目的端口号 编辑:程序博客网 时间:2024/05/04 23:09

xml:

<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="/ins_client_M_2_0/menustyle/Navigate.xsl" type="text/xsl" ?>
<Modules LoginInfo=" 【用户:系统管理员】 【部门:机电物资部】 【IP:127.0.0.1】 【登录时间:13:54:46】 【登录次数:7530】">
 <Module Name="设备管理" Index="0" Icon="0014.GIF" Url="">
  <FuncPages>
   <FuncPage Href="modules/machine/requiredplan/planquerybyyear.aspx" Name="需求计划" Icon="0015.gif"/>
   <FuncPage Href="modules/machine/purchase/purchaseplan/planquery.aspx" Name="采购计划" Icon="001.gif"/>
   <FuncPage Href="modules/machine/purchase/purchaseprice/inviteinfo.aspx" Name="采购招标" Icon="001.gif"/>
   <FuncPage Href="modules/machine/purchase/contract/contractinfo.aspx" Name="采购合同" Icon="0012.gif"/>
   <FuncPage Href="modules/machine/purchase/acceptcheck/acceptcheckinfo.aspx" Name="验收入库" Icon="0013.gif"/>
   <FuncPage Href="modules/machine/record/baseinfo/machinfo.aspx" Name="基本信息" Icon="0014.GIF"/>
   <FuncPage Href="modules/machine/transfer/transferquery.aspx" Name="设备调动" Icon="0015.gif"/>
   <FuncPage Href="modules/machine/run/usinganalyse/usinganalyse.aspx" Name="运行维护" Icon="0012.gif"/>
   <FuncPage Href="modules/machine/run/accident/accidentrecordcheck.aspx" Name="事故管理" Icon="0013.gif"/>
   <FuncPage Href="modules/machine/run/repair/repairapplyplanquery.aspx" Name="设备大修" Icon="0015.gif"/>
   <FuncPage Href="modules/machine/run/sell/sellquery.aspx" Name="设备让售" Icon="0013.gif"/>
   <FuncPage Href="modules/machine/run/discard/discardquery.aspx" Name="设备报废" Icon="0013.gif"/>
   <FuncPage Href="modules/machine/depreciation/machdepreinfo.aspx" Name="设备折旧" Icon="001.gif"/>
   <FuncPage Href="modules/machine/rent/contract/innerrentcontract.aspx" Name="设备租赁" Icon=""/>
   <FuncPage Href="modules/machine/certifycate/baseinfomanage.aspx" Name="操作证书" Icon=""/>
   <FuncPage Href="modules/machine/report/reportlistforasset.aspx" Name="设备报表" Icon="0011.gif"/>
  </FuncPages>
 </Module>
 <Module Name="物资管理" Index="1" Icon="001.gif" Url="">
  <FuncPages>
   <FuncPage Href="modules/material/base/materstockdictmanage.aspx" Name="仓库定义" Icon=""/>
   <FuncPage Href="modules/material/base/matertypemanage.aspx" Name="物资定义" Icon=""/>
   <FuncPage Href="modules/material/plan/materownerprovideplanmanage.aspx" Name="物资需求" Icon=""/>
   <FuncPage Href="modules/material/plan/materprovidermanage.aspx" Name="物资采购" Icon=""/>
   <FuncPage Href="modules/material/stock/materstockmonthdatainit.aspx" Name="库存管理" Icon=""/>
   <FuncPage Href="modules/material/daily/materdailyinrecordlist.aspx" Name="到货登记" Icon=""/>
   <FuncPage Href="modules/material/dailyspecial/materdailyoilinrecord.aspx" Name="特材管理" Icon=""/>
   <FuncPage Href="modules/material/turnover/turnovermaterinstock.aspx" Name="周材管理" Icon=""/>
   <FuncPage Href="modules/material/flow/materinstockbilldetaillist.aspx" Name="物资流转" Icon=""/>
   <FuncPage Href="modules/material/tool/matertoolinstock.aspx" Name="工器具管理" Icon=""/>
   <FuncPage Href="modules/material/report/materinstockreport.aspx" Name="物资报表" Icon=""/>
  </FuncPages>
 </Module>
 <Module Name="项目管理" Index="2" Icon="" Url="">
  <FuncPages>
   <FuncPage Href="modules/project/base/projectinfo.aspx" Name="项目定义" Icon=""/>
  </FuncPages>
 </Module>
 <Module Name="合同管理" Index="3" Icon="" Url="">
  <FuncPages>
   <FuncPage Href="modules/contract/base/contractinfo.aspx" Name="合同管理" Icon=""/>
  </FuncPages>
 </Module>
 <Module Name="网站管理" Index="4" Icon="" Url="">
  <FuncPages>
   <FuncPage Href="modules/insnews/manage/typemanage.aspx" Name="新闻管理" Icon=""/>
  </FuncPages>
 </Module>
 <Module Name="综合查询" Index="5" Icon="0016.gif" Url="">
  <FuncPages>
   <FuncPage Href="modules/query/machine/base/machbasicinforeport.aspx" Name="设备资产信息" Icon=""/>
   <FuncPage Href="modules/query/machine/purchase/machpurchaseinforeport.aspx" Name="设备采购信息" Icon=""/>
   <FuncPage Href="modules/query/mater/purchase/materpurchaseinforeport.aspx" Name="物资采购信息" Icon=""/>
   <FuncPage Href="modules/query/machine/run/machruninfoquery.aspx" Name="设备运行信息" Icon=""/>
   <FuncPage Href="modules/query/mater/consume/matercostinforeport.aspx" Name="物资消耗信息" Icon=""/>
   <FuncPage Href="modules/query/mater/stock/materstockinforeport.aspx" Name="物资库存信息" Icon=""/>
  </FuncPages>
 </Module>
 <Module Name="系统管理" Index="6" Icon="001.gif" Url="">
  <FuncPages>
   <FuncPage Href="modules/rightctrl/enterprisestructdefine.aspx" Name="机构管理" Icon="001.gif"/>
   <FuncPage Href="modules/rightctrl/modulesdefine.aspx" Name="权限管理" Icon="001.gif"/>
   <FuncPage Href="modules/common/inscommontypedef.aspx" Name="参数配置" Icon="001.gif"/>
   <FuncPage Href="modules/systemmgr/loglist.aspx" Name="系统监控" Icon="001.gif"/>
   <FuncPage Href="modules/common/report/insreportmgr.aspx" Name="E表配置" Icon=""/>
   <FuncPage Href="modules/portal/portalproviderchooselist.aspx" Name="首页配置" Icon=""/>
   <FuncPage Href="modules/insnoticeservice/insregisteredmsgservice.aspx" Name="消息服务" Icon=""/>
   <FuncPage Href="modules/workflow/workflowmgr.aspx" Name="任务管理" Icon=""/>
  </FuncPages>

 </Module>
</Modules>

xsl:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format">
  <xsl:output method="html" />
  <xsl:template match="/">
    <xsl:variable name="relativeHrefPrefix">
      <xsl:value-of select="/genericPage/filesystem-info/@relativeAddressPrefix" />
    </xsl:variable>
    <xsl:variable name="transp">
      <xsl:value-of select="$relativeHrefPrefix" />images/layout/transp.gif
    </xsl:variable>
    <HTML>
      <head>
        <title>叶杨.2009.7.18</title>
 <style>
 A:link,A:active,A:visited{TEXT-DECORATION:none ;Color:#4455aa}
 A:hover{TEXT-DECORATION: underline;Color:#ff0000}
 BODY
 {
  FONT-FAMILY:  宋体;
  font-size:9pt;
  scrollbar-face-color: #DEE3E7;
  scrollbar-highlight-color: #FFFFFF;
  scrollbar-shadow-color: #DEE3E7;
  scrollbar-3dlight-color: #D1D7DC;
  scrollbar-arrow-color:  #006699;
  scrollbar-track-color: #EFEFEF;
  scrollbar-darkshadow-color: #98AAB1;
  background-image: url("styleimage/bg.gif");
 }
 TABLE
 {
   font-size:9pt;
   font-family: 宋体;
   width:100%;
 }
 TABLE.NOEXPAND{
   width:0%;
 }
 TD
 {
   height:23px;
 }
 </style>
        <SCRIPT language="javascript">
 var preDiv = null;
 function showLayer(theImg,theParent,theLayerName)
 {
   theName = "lay_" + theLayerName;
   theLayer = document.getElementById(theName);
   if(theLayer.style.display == "block")
   {
     theLayer.style.display = "none";
     theImg.src = "images/leftframe/img1.gif";
   }
   else
   {
     theLayer.style.display = "block";
     theImg.src = "images/leftframe/img3.gif";
   }
   //叶杨:以下为仅有当前层展开效果处理
   if(preDiv == null)
   {
  preDiv = theLayer;
   }
   else
   {
  preDiv.style.display = "none";
  var index = preDiv.id.substr(4);
  var imgObj = document.getElementById("img_" + index);
  imgObj.src = "images/leftframe/img1.gif";
  preDiv = theLayer;
   }  
 }
 function makevisible(cur,which)
 {
   if (which==0)
   {
     cur.filters.alpha.opacity=0
   }
   else
   {
     cur.filters.alpha.opacity=0
   }
 } 
  //叶杨:以下为仅有当前链接红色效果处理
  var preLink = null;
         function Setstyle()
         {
  var obj = window.event.srcElement;
  obj.style.color = "red";
  if(preLink == null)
  {
   preLink = obj;
  }
  else
  {
   if(preLink.href!= "#")
    preLink.style.color = "black";
   preLink = obj;
  }
  
         }
 
        </SCRIPT>
      </head>
      <body bgcolor="" >     
        <script language="javascript">
          /*叶杨:关闭.SetState('<xsl:value-of select="/Modules/@LoginInfo" />')*/
        </script>
     <div id="LayerTop" style="position:absolute; left:3px; top:1px; width:200px; height:219px; z-index:1">
       <xsl:for-each select="/Modules/Module">
  <xsl:apply-templates select="." mode="Main" />
  <xsl:apply-templates select="." mode="Item" />
       </xsl:for-each>           
     </div> 
      </body>
    </HTML>
  </xsl:template> 
  <xsl:template match="Module" mode="Main">
      <!--模块-->
       <table border="0" cellspacing="0" cellpadding="0"  class="NOEXPAND">
     <tr>     
  <td class="NOBORDER">
  <img src="images/leftframe/img1.gif" width="16" height="16">
   <xsl:attribute name="id"><xsl:value-of select="concat('img_',@Index)" /></xsl:attribute>
   <xsl:attribute name="onclick">
    showLayer(this,LayerTop,<xsl:value-of select="@Index" />)
   </xsl:attribute>
  </img>
  </td>     
  <td class="NOBORDER" colspan="3">
  <a>
   <xsl:attribute name="onclick">showLayer(<xsl:value-of select="concat('img_',@Index)" />,LayerTop,<xsl:value-of select="@Index" />)</xsl:attribute>
   <xsl:attribute name="style">color:black</xsl:attribute> 
   <xsl:value-of select="@Name" />
  </a>
  </td>
     </tr>
 </table>              
  </xsl:template>
  <xsl:template match="Module" mode="Item">
    <!--菜单-->
    <div style="display:none" >       
      <xsl:attribute name="id">lay_<xsl:value-of select="@Index" /></xsl:attribute>
      <xsl:for-each select="./FuncPages/FuncPage">
        <table border="0" cellspacing="0" cellpadding="0" class="NOEXPAND">
   <tr>
         <td class="NOBORDER">
  <img src="images/leftframe/img4.gif" width="16" height="16" style="filter:alpha(opacity=0)" onMouseOver="makevisible(this,0)" onMouseOut="makevisible(this,1)"/>
  </td>
  <td class="NOBORDER"><img src="images/leftframe/img3.gif" width="16" height="16"/></td>
  <td class="NOBORDER" colspan="1">
  <xsl:apply-templates select="." />
  </td>
   </tr>
 </table>       
      </xsl:for-each>
    </div>
  </xsl:template> 
   <xsl:template match="FuncPage">
    <!--链接-->
 <a target="content">
   <xsl:attribute name="onclick">Setstyle()</xsl:attribute>
   <xsl:attribute name="href"><xsl:value-of select="@Href" /></xsl:attribute>
   <xsl:attribute name="style">color:black</xsl:attribute>
   <xsl:attribute name="title">
     <xsl:value-of select="@Name" />
   </xsl:attribute>
   <xsl:value-of select="@Name" />
 </a>
  </xsl:template>
</xsl:stylesheet>

output:

输出效果

原创粉丝点击