kwilliams Posted October 20, 2006 Share Posted October 20, 2006 I've been able to pull and assign a XSLT parameter in ASP, but I'm now converting my site over to ASP.NET. I'm using XML, XSLT, ASP.NET, and VB.NET for this new site using the xslTransform method, and I want to pull an XSLT parameter into the ASP.NET page, and then assign a new value to that XSLT paramater using a form that's created from the XSLT stylesheet. This is what I have so far:XSLT parameter <xsl:param name="fname_value" select="''" /> ASP.NET code <%@ Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" AspCompat="true" Debug="true" %><%@ import Namespace="System.Data" %><%@ import Namespace="System.Web" %><%@ import Namespace="System.Web.UI" %><%@ import Namespace="System.Web.UI.WebControls" %><%@ import Namespace="System.Web.UI.HtmlControls" %><%@ import Namespace="System.Xml" %><%@ import Namespace="System.Xml.Xsl" %><%@ import Namespace="System.Xml.XPath" %><%@ import Namespace="System.IO" %><%@ Import Namespace="System.Text" %><script language="vb" runat="server"> Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Dim xmlURL As String = "form.xml" Dim xslURL As String = "form.xsl" 'Assign dynamic url for this page xslTransform.DocumentSource = xmlURL xslTransform.TransformSource = xslURL End Sub</script><html><body> <asp:Xml id="xslTransform" runat="server"></asp:Xml></body></html> I haven't found much on how to do this in ASP.NET, but I did find a great article from a book titled "XSLT and ASP.NET" at http://www.topxml.com/dotnet/articles/xslt...ransforming_XML under the ".NET Classes Involved in Transforming XML" section. The book/article is written in C#, and I use VB.NET. But I'm using a C# to VB.NET converter at http://www.developerfusion.co.uk/utilities...csharptovb.aspx to help out.As far as I can see, this article doesn't have any examples involving pulling and assigning a value for an XSLT parameter using the method that I'm using, so I'm not sure where to go with this. So I'm looking for some direction on this subject. I'd appreciate any help. Thanks. Link to comment Share on other sites More sharing options...
aalbetski Posted October 20, 2006 Share Posted October 20, 2006 This is an example (fragment) from a project of mine. This was done in C#, but it should point you in the right direction XslTransform xsl = new XslTransform(); xsl.Load(MapPath("StyleSheet.xslt"));XsltArgumentList xsltArgs = new XsltArgumentList();xsltArgs.AddParam("ParentTable" ,"","Arg1");xsltArgs.AddParam("ChildTable" ,"","Arg2");this.xmlReport.Document = GetXMLDataSource();this.xmlReport.TransformArgumentList = xsltArgs;this.xmlReport.Transform = xsl; Link to comment Share on other sites More sharing options...
kwilliams Posted October 20, 2006 Author Share Posted October 20, 2006 Thanks for the reply aalbetski.When I converted your code to VB.NET and tried your suggestion, I received this error message: BC30002: Type 'XslTransform' is not defined. This is the converted code that I'm using: Dim xsl As XslTransform = New XslTransformxsl.Load(MapPath("form.xsl"))Dim xsltArgs As XsltArgumentList = New XsltArgumentListxsltArgs.AddParam("fname_value", "", "Hello")Me.xmlReport.Document = GetXMLDataSourceMe.xmlReport.TransformArgumentList = xsltArgsMe.xmlReport.Transform = xsl From what you can see, is there something that I'm not doing properly? Link to comment Share on other sites More sharing options...
aspnetguy Posted October 20, 2006 Share Posted October 20, 2006 You're using .Net 2.0 right? XslTransform is obsolete in 2.0. http://msdn2.microsoft.com/en-us/library/s...ltransform.aspxI believe the new class is XslCompiled Transform. http://www.topxml.com/XmlDocument/re-5322_...-mode-XSLT.aspx Link to comment Share on other sites More sharing options...
aalbetski Posted October 20, 2006 Share Posted October 20, 2006 Here is an entire project in VB (written just for this) Imports System.XmlImports System.Xml.XslPublic Class WebForm1 Inherits System.Web.UI.Page#Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent() End Sub Protected WithEvents Xml1 As System.Web.UI.WebControls.Xml 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub#End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim xmlSource As New XmlDocument Dim xslTrans As New XslTransform Dim xslArgs As New XsltArgumentList xmlSource.Load(Server.MapPath("cat.xml")) xslTrans.Load(Server.MapPath("cat.xsl")) xslArgs.AddParam("param1", "", "Hello") Me.Xml1.Document = xmlSource Me.Xml1.TransformArgumentList = xslArgs Me.Xml1.Transform() = xslTrans End SubEnd Class Link to comment Share on other sites More sharing options...
aspnetguy Posted October 20, 2006 Share Posted October 20, 2006 aalbetski is this written in VB.Net 2.0? According tot he MSDN specification for XslTransform, it is obsolete in 2.0.Am I wrong on this? I don't use XML much so I am unsure. Link to comment Share on other sites More sharing options...
aalbetski Posted October 20, 2006 Share Posted October 20, 2006 No, this is 1.1.I'll do a 2.0 one when I get some more time Link to comment Share on other sites More sharing options...
kwilliams Posted October 24, 2006 Author Share Posted October 24, 2006 After looking up XslTransform's documentation, I also realized that it was now obsolete in 2.0. Our current test server will start running 2.0 exclusively soon, so I'll have to change my site's master page to reflect this change.I really appreciate your help, as I know that you are busy. And when you have time, it would be very helpful if you could show me an example in 2.0 as you stated. So thanks for the offer, and all of your help. Link to comment Share on other sites More sharing options...
aalbetski Posted November 16, 2006 Share Posted November 16, 2006 Here is the code for a VB.NET (2.0) app transforming XML using XSLT and a XmlWebControl. It's actually simpler than before. This is not the same XML that was used in this thread, but the syntax is the same Dim xa As New XsltArgumentList xa.AddParam("color", "", "red") Me.Xml1.TransformArgumentList = xa Me.Xml1.DocumentSource = (MapPath("items1.xml")) Me.Xml1.TransformSource = (MapPath("items1.xsl")) Link to comment Share on other sites More sharing options...
kwilliams Posted November 16, 2006 Author Share Posted November 16, 2006 Here is the code for a VB.NET (2.0) app transforming XML using XSLT and a XmlWebControl. It's actually simpler than before. This is not the same XML that was used in this thread, but the syntax is the same Dim xa As New XsltArgumentList xa.AddParam("color", "", "red") Me.Xml1.TransformArgumentList = xa Me.Xml1.DocumentSource = (MapPath("items1.xml")) Me.Xml1.TransformSource = (MapPath("items1.xsl")) Wow, thanks for the info. I'll give it a try, and I'll let you know how it works for me:) 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