欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

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

程序员文章站 2024-03-01 22:21:28
复制代码 代码如下:<%@ page language="c#" autoeventwireup="true" codebehind="webform1.aspx.c...

复制代码 代码如下:

<%@ 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>