Jump to content

Newbie: ASP.NET/XML Transformation Problem


kwilliams

Recommended Posts

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:

<%@ 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 variablesDim 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 separaterDim path_slash As String = "/"'Declare transformed variablesDim page_path As String, dir_path As String, subdir1_path As String, subdir2_path As String'If dir is emptyIf dir = "" Thendir_path = ""Elsedir_path = dir + path_slashEnd If'If subdir1 is emptyIf subdir1 = "" Thensubdir1_path = ""Elsesubdir1_path = subdir1 + path_slashEnd If'If subdir2 is emptyIf subdir2 = "" Thensubdir2_path = ""Elsesubdir2_path = subdir2 + path_slashEnd If'If page is not emptyIf page <> "" Thenpage_path = pageEnd If%><%'Declare XML and XSL file pathsDim xmlURL As String, xslURL As StringxmlURL = "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 LATERDim xml = Server.CreateObject("MSXML2.DOMDocument.3.0")xml.async = falsexml.load(xmlURL)'Load XSL'Dim xsl = Server.CreateObject("Microsoft.XMLDOM") 'DELETE LATERDim xsl = Server.CreateObject("MSXML2.DOMDocument.3.0")xsl.async = falsexsl.load(xslURL)'Transform fileResponse.Write(xml.transformNode(xsl))%>

...and the new ASP.NET page I've developed is so far like this:

<%@ 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><!-- This method DOES NOT work --></body></html>

When I use this property to transform the 2 files:

'Transform file		'Response.Write(xml.transformNode(xsl))

...it comes through fine.But when I attempt to use this method to transform the 2 files:

<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.

Link to comment
Share on other sites

Well, I solved this one after further research and testing. I just needed to assign the form field xmlTransorm within the code of the document to retain a dynamic page. So this is what I did:

<script language="VB" runat="server">Dim xmlURL As String, xslURL As StringxmlURL = "/MAINDIRECTORY/" + dir_path + subdir1_path + subdir2_path + "docs/xml/" + page_path + ".xml"xslURL = "/MAINDIRECTORY/" + dir_path + subdir1_path + subdir2_path + "docs/xslt/" + page_path + ".xsl"'Assign dynamic urlS for this pagexslTransform.DocumentSource = xmlURLxslTransform.TransformSource = xslURL</script><html><body><form runat="server"> <asp:Xml id="xslTransform" runat="server"></asp:Xml></form></body></html>

...and it worked great. There's a great online article that comes from the book "XSLT for ASP.NET" that talks about this at http://www.topxml.com/dotnet/articles/xslt/default.asp. Even thought I code in VB.NET, and this book uses C# for its examples, I definitely intend to get this book.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...