.net中使用xsl文件作为导航菜单的小例子


  本文标签:xsl,导航

复制代码 代码如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="testweb.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
     <asp:Xml TransformSource="XSLTFile1.xslt" ID="minanva" runat="server"></asp:Xml>
    </div>
    </form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace testweb
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            minanva.DocumentContent = @"<站点导航列表 来访员工=>
                                          <站点导航 站点名称=设计计划 站点编号=EPM 站点链接=../NWEPDI.EPM.WEB/../Project/ProjectList.aspx?QueueType=EPM0101 />
                                          <站点导航 站点名称=设计作业 站点编号=DDM 站点链接=../MoEngineer/ProjectMgr.aspx />
                                          <站点导航 站点名称=设计流程 站点编号=DFM 站点链接=../MoFlow/CWorkItemList.aspx?QueueType=DFM0101 />
                                          <站点导航 站点名称=印务管理 站点编号=PPM 站点链接=../MoPrint/PrintMgr.aspx?QueueType=PPM0101 />
                                          <站点导航 站点名称=工时管理 站点编号=WHM 站点链接=../MoWorkHour/HourMgrPrj.aspx?QueueType=WHM0103 />
                                          <站点导航 站点名称=电子归档 站点编号=ARC 站点链接=../MoArchieve/ProjectMgr.aspx?QueueType=ARC0101 />
                                          <站点导航 站点名称=统计报表 站点编号=SSM 站点链接=../MoReports/ReportView.aspx?QueueType=SSM0101 />
                                          <站点导航 站点名称=资料管理 站点编号=DAM 站点链接=../MoDocument/ProjectFileMgr.aspx?QueueType=DAM0101 />
                                          <站点导航 站点名称=系统管理 站点编号=DSM 站点链接=../MoAdmin/CommonRuleList.aspx?QueueType=DSM0101 />
                                        </站点导航列表>";
        }
    }
}


<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="xml" indent="yes"/>
  <xsl:template match="//站点导航列表">
    <div>
      <ul>
        <li>导航</li>
        <xsl:for-each select="站点导航">
          <li>
            <xsl:value-of select="@站点名称"/>
            <xsl:attribute name="id">
              <xsl:value-of select="@站点编号"/>
            </xsl:attribute>
            <xsl:attribute name="href">
              <xsl:value-of select="@站点链接"/>
            </xsl:attribute>
          </li>
        </xsl:for-each>
      </ul>
    </div>
  </xsl:template>
</xsl:stylesheet>