Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 28th, 2006, 10:02 AM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default Newbie: ASP.NET/XML Transformation Problem

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
 
Old August 28th, 2006, 02:40 PM
Banned
 
Join Date: Jul 2005
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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:

Code:
<script language="VB" runat="server">
Dim xmlURL As String, xslURL As String
xmlURL = "/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 page
xslTransform.DocumentSource = xmlURL
xslTransform.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.

KWilliams





Similar Threads
Thread Thread Starter Forum Replies Last Post
xml transformation to wml using asp.net arunagottimukkala ASP.NET 1.0 and 1.1 Professional 1 November 7th, 2007 07:23 AM
Problem in XML to XML transformation jkuravatti XSLT 2 May 5th, 2006 11:21 AM
XML transformation problem... muki XML 2 February 1st, 2006 02:55 AM
XML transformation problem... muki XSLT 0 January 31st, 2006 10:36 PM
Server side transformation with- XSL/XML, ASP, IIS kenneth02 Classic ASP XML 3 November 10th, 2003 10:14 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.