Click to See Complete Forum and Search --> : ADVICE WANTED: Which method is more efficient?


kwilliams
08-29-2006, 02:34 PM
I currently have a site that uses ASP.NET, VB.NET, XML, and XSLT using XSL Transformation in ASP.NET. My current method is this:
<script runat="server">
Sub Page_Load
'Pull page_qs querystring variable
Dim page_qs As String = Request.QueryString("page")
'Load XML file w/page_qs variable selected and assign page properties
Dim il_xmld As XmlDocument
Dim il_nodelist As XmlNodeList
Dim il_node As XmlNode
'Create the XML Document
il_xmld = New XmlDocument()
'Load the Xml file
il_xmld.Load("links.xml")
'Get the list of name nodes
il_nodelist = il_xmld.SelectNodes("/links/page[@id = '" & page_qs & "']")
'Loop through the nodes
For Each il_node In il_nodelist

'Get an Attribute Value
Dim page_id = il_node.Attributes.GetNamedItem("id").Value

'Pull XML nodes
dir_code = il_node.Item("dir_code").InnerText
subdir1_code = il_node.Item("subdir1_code").InnerText
subdir2_code = il_node.Item("subdir2_code").InnerText

'Page path creator
'If dir is empty
path_slash = "/"
If dir_code = "" Then
dir_path = ""
Else
dir_path = dir_code + path_slash
End If

'If subdir1 is empty
If subdir1_code = "" Then
subdir1_path = ""
Else
subdir1_path = subdir1_code + path_slash
End If

'If subdir2 is empty
If subdir2_code = "" Then
subdir2_path = ""
Else
subdir2_path = subdir2_code + path_slash
End If

'If page is not empty
If page_id <> "" Then
page_path = page_id
End If

'Declare XML and XSL file paths
Dim xmlURL As String, xslURL As String
xmlURL = "/DIRECTORY/" + dir_path + subdir1_path + subdir2_path + "docs/xml/" + page_path + ".xml"
xslURL = "/DIRECTORY/" + dir_path + subdir1_path + subdir2_path + "docs/xslt/" + page_path + ".xsl"
'Assign dynamic url for this page
xslTransform.DocumentSource = xmlURL
xslTransform.TransformSource = xslURL

'Load XML
Dim xml = Server.CreateObject("MSXML2.DOMDocument.3.0")
xml.async = false
xml.load(xmlURL)

'Load XSL
Dim xsl = Server.CreateObject("MSXML2.DOMDocument.3.0")
xsl.async = false
xsl.load(xslURL)

End Sub
</script>
<html>
<body>
<form runat="server">
<asp:Xml id="xslTransform" runat="server"></asp:Xml>
</form>
</body>
</html>

But I was wondering, would it be more or less efficient for me to create a function that transforms the XML and XSLT files in the code using the transformNode method by calling the function from a label in the form tag? I guess I'm thinking something like this:
<script runat="server">
Sub Page_Load
Function webdata
'Pull page_qs querystring variable
Dim page_qs As String = Request.QueryString("page")
'Load XML file w/page_qs variable selected and assign page properties
Dim il_xmld As XmlDocument

'.... SAME AS ABOVE
'Load XML
Dim xml = Server.CreateObject("MSXML2.DOMDocument.3.0")
xml.async = false
xml.load(xmlURL)

'Load XSL
Dim xsl = Server.CreateObject("MSXML2.DOMDocument.3.0")
xsl.async = false
xsl.load(xslURL)

'Transform file
webdata.Text = xml.transformNode(xsl)
End Function
End Sub
</script>
<html>
<body>
<form runat="server">
<asp:Label id="webdata" runat="server" />
</form>
</body>
</html>

NOTE: Please keep in mind that I'm a newbie to all of this, so I realize that my logic may not be correct in the second example.

Or is the difference so minor that it doesn't matter? I'd greatly appreciate some input on this. Thanks for any advice.

sirpelidor
08-30-2006, 08:28 PM
you won't be able to validate your aspx doc with xslt against w3c.

stick with either asp.net or xslt, don't mix'em both.

kwilliams
08-31-2006, 08:25 AM
you won't be able to validate your aspx doc with xslt against w3c. stick with either asp.net or xslt, don't mix'em both.
I'm really not sure what you're talking about, since I've had no problem with that so far. Using ASP.NET to pull XML data using XSLT Transformation is becoming more and more widely-used by lots of developers. You can see more information on it at different XML/XSLT forums like these:

http://www.webdeveloper.com/forum/forumdisplay.php?f=5
http://w3schools.invisionzone.com/index.php?showforum=10
http://p2p.wrox.com/forum.asp?FORUM_ID=79

The original question I posed on this post had to do with which method is better. If anyone has any advice on that, that would be great. Thanks.

sirpelidor
08-31-2006, 02:17 PM
sorry i got confuse your post with one of the project I did a while back...

back 2 ur original question.
the major diff between those 2 approaches are:
asp.net render ur code into html inf approach 1 where asp.net wrap ur xslt into a span tag in approach 2.

while both approach works, I think i perfer approach 1 over approach 2 because when it comes to "efficient", approach 1 has 1 less item to rend, where approach 2 not only have a extra span tag, but also additional view state info you won't need.

hope that helps...

kwilliams
08-31-2006, 02:28 PM
sorry i got confuse your post with one of the project I did a while back...Ok, that's fine.

back 2 ur original question.
the major diff between those 2 approaches are:
asp.net render ur code into html inf approach 1 where asp.net wrap ur xslt into a span tag in approach 2.

while both approach works, I think i perfer approach 1 over approach 2 because when it comes to "efficient", approach 1 has 1 less item to rend, where approach 2 not only have a extra span tag, but also additional view state info you won't need.

hope that helps...
Yes it does help. Thanks for your advice.