xsl實戰:通過xml產生功能菜單樹

來源:互聯網
上載者:User

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="Message Service" 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:

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.