⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 xsl-transform.aspx

📁 东软内部材料(四)asp等相关的教学案例 
💻 ASPX
字号:
<%@Page Language="C#"%>
<%@Import Namespace="System.Xml" %>
<%@Import Namespace="System.Xml.Xsl" %>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html><head>
<title>Transforming an Xml document using the XSLTransform object</title>
<!-- #include file="..\global\style.inc" -->
</head>
<body bgcolor="#ffffff">
<span class="heading">Transforming an Xml document using the XSLTransform object</span><hr />
<!--------------------------------------------------------------------------->

Using Xml document file:
<b><span id="outXmlURL" runat="server"></span></b><br />
Loaded XSL stylesheet file:
<b><span id="outXSLURL" runat="server"></span></b><br />
Written new HTML disk file:
<b><span id="outHTMLURL" runat="server"></span></b><br />
<div id="outError" runat="server">&nbsp;</div>
<div id="outResults" runat="server"></div>

<script language="C#" runat="server">

	void Page_Load(Object sender, EventArgs e)
	{
		// create physical path to booklist sample files (in same folder as ASPX page)
		string strCurrentPath = Request.PhysicalPath;
		string strXmlPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\")) + "\\booklist.xml";
		string strXSLPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\")) + "\\booklist.xsl";
		string strHTMLPath = strCurrentPath.Substring(0, strCurrentPath.LastIndexOf("\\")) + "\\booklist.html";
		outXmlURL.InnerHtml = "<a href='" + strXmlPath + "'>" + strXmlPath + "</a>";

		try
		{
			// create a new XslTransform object
			XslTransform objTransform = new XslTransform();

			// load the XSL stylesheet into the XSLTransform object
			objTransform.Load(strXSLPath);
			outXSLURL.InnerHtml = "<a href='" + strXSLPath + "'>" + strXSLPath + "</a>";

			// perform the transformation using the XSL file in the
			// XSLTransform and the Xml file path in strXmlPath
			// the result is sent to the disk file in strHTMLPath
			objTransform.Transform(strXmlPath, strHTMLPath);
			outHTMLURL.InnerHtml = "<a href='" + strHTMLPath + "'>" + strHTMLPath + "</a>";

		}
		catch (Exception objError)
		{
			// ------------ error handling code -------------

			// display error details
			outError.InnerHtml = "<b>* Error while accessing document</b>.<br />"
							+ objError.Message + "<br />" + objError.Source;
			return; //  and stop execution
		}

	}

</script>

<!--------------------------------------------------------------------------->
<!-- #include file="..\global\foot.inc" -->
</body>
</html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -