xsl-transform.aspx

来自「Code for VB.NET教程源码 很好的源码」· ASPX 代码 · 共 67 行

ASPX
67
字号
<%@Page Language="VB"%>
<%@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="vb" runat="server">

Sub Page_Load()

   'create physical path to booklist sample files (in same folder as ASPX page)
   Dim strCurrentPath As String = Request.PhysicalPath
   Dim strXMLPath As String = Left(strCurrentPath, InStrRev(strCurrentPath, "\")) & "booklist.xml"
   Dim strXSLPath As String = Left(strCurrentPath, InStrRev(strCurrentPath, "\")) & "booklist.xsl"
   Dim strHTMLPath As String = Left(strCurrentPath, InStrRev(strCurrentPath, "\")) & "booklist.html"
   outXMLURL.InnerHtml = "<a href=""" & strXMLPath & """>" & strXMLPath & "</a>"

   Try

      'create a new XslTransform object
      Dim objTransform As 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>"

   '------------ error handling code -------------
   Catch objError As Exception

      'display error details
      outError.innerHTML = "<b>* Error while accessing document</b>.<br />" _
          & objError.Message & "<br />" & objError.Source
      Exit Sub  ' and stop execution

   End Try

End Sub

</script>

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

⌨️ 快捷键说明

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