Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Nov 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Convert XslTransform to XslCompiledTransform

    Hi - I just converted an ASP.Net web app from 2.0 to 4.0 and the XslTransform code that I inherited no longer works in 4.0. I'm told I need to change the code to use XslCompiledTransform. Fine - but I can't figure out how to get XslCompiledTransform to do exactly what I need it to do. I have an XSL file in my project. I do not have an XML or HTML file. The old code read as follows:
    Code:
    using (DataSet data = DataGateway.getAbsence(TripNum)) 
    { 
      data.DataSetName = "Absence"; 
      data.Tables[0].TableName = "Employee"; 
      XmlDataDocument xmldoc = new XmlDataDocument(Data); 
      XslTransform xslt = new XslTransform; 
      string xsltfile = "myfile.xsl"; 
      xslt.Load(xsltfile); 
      TextWriter writer = new StringWriter(); 
      xslt.Transform(xmldoc, null, writer, null); 
      MailMessage mail = new MailMessage(); 
      mail.Body = writer.ToString(); 
      mail.From = "me"; 
      mail.To = "you"; 
      //more code to send mail...... 
    }
    I've tried to rewrite this by substituting and XsltCompiledTransform object for the XslTransform object, and an XmlWriter object for the TextWriter object, but the xslt.Transform line complains about my using an XmlDataDocument as input. It suggests an XmlReader instead, but I don't know how to pass the data from my DataSet into an XmlReader. Or perhaps XslCompiledTransform is not the way to go Does anyone know?

    Thanks!

  • #2
    New Coder
    Join Date
    Nov 2010
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I got a response to this issue from Javeed M Shaikh on C-SharpCorner.com (big shout out to Javeed). This works beautifully converting a Dataset to XML:

    Code:
    XmlTextReader mXmlTextReader = new XmlTextReader(data.GetXml(),XmlNodeType.Document, null);


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •