I'm trying to convert an ASP page that uses XML/XSLT Transformation into an ASP.NET page that uses the same transformation. The old ASP page was like this:
Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" aspcompat="true" Debug="true" %>
<%@ OutputCache Duration="10" VaryByParam="*"%>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Xml" %>
<%@ import Namespace="System.Text.RegularExpressions" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<%
'Declare querystring variables
Dim page As String = Request.QueryString("page")
Dim dir As String = Request.QueryString("dir")
Dim subdir1 As String = Request.QueryString("subdir1")
Dim subdir2 As String = Request.QueryString("subdir2")
Dim subleftnav As String = Request.QueryString("subleftnav")
%>
<%
'Path separater
Dim path_slash As String = "/"
'Declare transformed variables
Dim page_path As String, dir_path As String, subdir1_path As String, subdir2_path As String
'If dir is empty
If dir = "" Then
dir_path = ""
Else
dir_path = dir + path_slash
End If
'If subdir1 is empty
If subdir1 = "" Then
subdir1_path = ""
Else
subdir1_path = subdir1 + path_slash
End If
'If subdir2 is empty
If subdir2 = "" Then
subdir2_path = ""
Else
subdir2_path = subdir2 + path_slash
End If
'If page is not empty
If page <> "" Then
page_path = page
End If
%>
<%
'Declare XML and XSL file paths
Dim xmlURL As String, xslURL As String
xmlURL = "http://SERVERNAME/MAINDIRECTORY/" + dir_path + subdir1_path + subdir2_path + "docs/xml/" + page_path + ".xml"
xslURL = "http://SERVERNAME/MAINDIRECTORY/" + dir_path + subdir1_path + subdir2_path + "docs/xslt/" + page_path + ".xsl"
'Test
'Response.Write(xmlURL + "<br />" + xslURL)
%>
<%
'Load XML
'Dim xml = Server.CreateObject("Microsoft.XMLDOM") 'DELETE LATER
Dim xml = Server.CreateObject("MSXML2.DOMDocument.3.0")
xml.async = false
xml.load(xmlURL)
'Load XSL
'Dim xsl = Server.CreateObject("Microsoft.XMLDOM") 'DELETE LATER
Dim xsl = Server.CreateObject("MSXML2.DOMDocument.3.0")
xsl.async = false
xsl.load(xslURL)
'Transform file
Response.Write(xml.transformNode(xsl))
%>
...and the new ASP.NET page I've developed is so far like this:
Code:
<%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" AspCompat="true" Debug="true" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System" %>
<%@ import Namespace="System.IO" %>
<%@ import Namespace="System.Xml" %>
<%@ import Namespace="System.Text.RegularExpressions" %>
<script runat="server">
Sub Page_Load
'To import XML/XSLT Transformation using DOM
'Declare querystring variables
Dim page As String = Request.QueryString("page")
Dim dir As String = Request.QueryString("dir")
Dim subdir1 As String = Request.QueryString("subdir1")
Dim subdir2 As String = Request.QueryString("subdir2")
Dim subleftnav As String = Request.QueryString("subleftnav")
'Path separater
Dim path_slash As String = "/"
'Declare transformed variables
Dim page_path As String, dir_path As String, subdir1_path As String, subdir2_path As String
'If dir is empty
If dir = "" Then
dir_path = ""
Else
dir_path = dir + path_slash
End If
'If subdir1 is empty
If subdir1 = "" Then
subdir1_path = ""
Else
subdir1_path = subdir1 + path_slash
End If
'If subdir2 is empty
If subdir2 = "" Then
subdir2_path = ""
Else
subdir2_path = subdir2 + path_slash
End If
'If page is not empty
If page <> "" Then
page_path = page
End If
'Declare XML and XSL file paths
Dim xmlURL As String, xslURL As String
xmlURL = "http://SERVERNAME/MAINDIRECTORY/" + dir_path + subdir1_path + subdir2_path + "docs/xml/" + page_path + ".xml"
xslURL = "http://SERVERNAME/MAINDIRECTORY/" + dir_path + subdir1_path + subdir2_path + "docs/xslt/" + page_path + ".xsl"
'Response.Write(xmlURL + "<br />" + xslURL) 'Test
'Load XML
'Dim xml = Server.CreateObject("Microsoft.XMLDOM") 'DELETE LATER
Dim xml = Server.CreateObject("MSXML2.DOMDocument.3.0")
xml.async = false
xml.load(xmlURL)
'Load XSL
'Dim xsl = Server.CreateObject("Microsoft.XMLDOM") 'DELETE LATER
Dim xsl = Server.CreateObject("MSXML2.DOMDocument.3.0")
xsl.async = false
xsl.load(xslURL)
'Transform file
'Response.Write(xml.transformNode(xsl)) 'This method DOES work
End Sub
</script>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head></head>
<body>
<form runat="server">
<asp:Xml id="xslTransform" runat="server" DocumentSource="<%=(xmlURL)%>" TransformSource="<%=(xslURL)%>"></asp:Xml>
</form>
</body>
</html>
When I use this property to transform the 2 files:
Code:
'Transform file
'Response.Write(xml.transformNode(xsl))
...it comes through fine.
But when I attempt to use this method to transform the 2 files:
Code:
<form runat="server">
<asp:Xml id="xslTransform" runat="server" DocumentSource="<%=(xmlURL)%>" TransformSource="<%=(xslURL)%>"></asp:Xml>
</form>
...I receive this error message:
Exception Details: System.ArgumentException: Illegal characters in path.
Source Error: An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
I'm wanting to use the second method because I want to load the data directly in the <body> tag of the page. If anyone can see what I'm doing wrong, and let me know how to correct it, that would be greatly appreciated. Thanks.
KWilliams