kwilliams Posted August 29, 2006 Share Posted August 29, 2006 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. Link to comment Share on other sites More sharing options...
pulpfiction Posted August 29, 2006 Share Posted August 29, 2006 guess both ways dont make much of a difference. but the second way of writing a set of code in a function and calling it in the sub would be better, as you can use that code again. and gives a clarity to the code as we can easily identify the actions performed when put seperate. small change you need to do is, you cannot write a function inside a Sub. <script runat="server">sub sname()..... code......fnname() 'function call........end subpublic function fnname()...... code .......end function</script>This will be the structure for the 2nd method. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now