所以我使用下面的代码进行xslt转换。但我对ASP.NET开发很新,所以错误有点误导。此代码生成一个错误,指出它不了解物理路径,只了解虚拟路径。什么是虚拟路径?如何从指定的物理路径创建虚拟路径?
<%@ Master Language="C#" AutoEventWireup="true" CodeBehind="Site.master.cs" Inherits="ViewerASP.SiteMaster" %>
<%@ Import Namespace="System.Xml" %>
<%@ Import Namespace="System.Xml.Xsl" %>
<%@ Import Namespace="System.Xml.XPath" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head runat="server">
<title>Viewer</title>
<link href="~/Styles/Site.css" rel="stylesheet" type="text/css" />
<script language="C#" runat="server">
public void Page_Load(Object sender, EventArgs E) {
string xmlPath = Server.MapPath("physicaladdresshere");
string xslPath = Server.MapPath("physicaladdresshere");
//Instantiate the XPathDocument Class
XPathDocument doc = new XPathDocument(xmlPath);
//INstantiate the XslTransform Class
XslTransform transform = new XslTransform();
transform.Load(xslPath);
//Custom format the indenting of the output document using XmlTextWriter
XmlTextWriter writer = new XmlTextWriter(Response.Output);
writer.Formatting = Formatting.Indented;
writer.Indentation=4;
transform.Transform(doc,null,writer);
}
</script>
<asp:ContentPlaceHolder ID="HeadContent" runat="server">
</asp:ContentPlaceHolder>
</head>
<div class="main">
<asp:ContentPlaceHolder ID="MainContent" runat="server"/>
</div>
</body>
</html>
答案 0 :(得分:1)
Server.MapPath
将虚拟路径(即虚拟IIS目录中的路径)映射到服务器上的物理路径。显然你不需要它,因为你已经拥有一个绝对的服务器端路径。只需删除这些Server.MapPath
来电:
string xmlPath = "C:\\Users\\kyle\\Desktop\\file.xml";
...