Folks, I'm running into some performance issues with my Xsl transformations .
I've done a ton of debugging and digging around, and have come to the
conclusion that the performance issues are NOT caused by slow stored
procedures, or bad XSL/Ts.
I came to this conclusion by doing a test transformation in client-side code
instead of server side aspx, as shown at the bottom of this post. The
transformations were super-fast. However, the client-side javascript isn't a
viable solution for my application.
I'm sure that different versions of the XMLDOM are being used when the code
is client-side as opposed to using System.Xml.Xsl.
Here's my C# code. What I'm trying to do is write out an HTML file of my
transformation.
// Create a FileStream to write with
System.IO.FileS tream fs = new System.IO.FileS tream(exportPat h,
System.IO.FileM ode.Create);
// Create an XmlTextWriter for the FileStream
System.Xml.XmlT extWriter oXmlTextWriter = new
System.Xml.XmlT extWriter(fs, System.Text.Enc oding.Unicode);
try
{
// Set up the XmlResolver
XmlUrlResolver oXmlUrlResolver = new XmlUrlResolver( );
oXmlUrlResolver .Credentials = CredentialCache .DefaultCredent ials;
// Set up the XslTransform
System.Xml.Xsl. XslTransform oXslTransform = new
System.Xml.Xsl. XslTransform();
oXslTransform.L oad(MyXslPath, oXmlUrlResolver );
// Perform Transformation
XmlDataDocument oXmlDataDocumen t = new XmlDataDocument (MyDataSet);
oXslTransform.T ransform(oXmlDa taDocument, null, oXmlTextWriter,
oXmlUrlResolver );
// Clean up
oXmlTextWriter. Close();
return exportPath; // defined elsewhere
}
catch (Exception ex)
{
oXmlTextWriter. Close();
System.IO.File. Delete(exportPa th);
ExceptionManage r.Publish(ex);
throw(ex);
}
The code works, but it's slow. It was suggested that I use an XPathDocument
instead of an XmlDataDocument . How would I do that?
Any suggestions? Thank You
Client-Side Transformation
<%
var sXml = "MyXml.Xml"
var sXsl = "MyXsl.xsl"
var oXmlDoc = Server.CreateOb ject("MICROSOFT .XMLDOM");
var oXslDoc = Server.CreateOb ject("MICROSOFT .XMLDOM");
oXmlDoc.async = false;
oXslDoc.async = false;
oXmlDoc.load(Se rver.MapPath(sX ml));
oXslDoc.load(Se rver.MapPath(sX sl));
Response.Write( oXmlDoc.transfo rmNode(oXslDoc) );
%>