Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
70
Binding via XML/XSLT - Deprecated code
posted

While working with ASP.NET 1.1 several years ago, a developer who has since left came up with the following code to bind to a heirarchical DataSet and uses XSLT to transform the data.

using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;

public void UltraWebTree_OrgTableBind(DataTable table, Infragistics.WebUI.UltraWebNavigator.UltraWebTree treeControl, int topOrgId) {

ds.Tables.Add( table );

DataRelation drel = new DataRelation("ORG_RECURSIVE",
       ds.Tables[table.TableName].Columns["Org_ID"],
       ds.Tables[table.TableName].Columns["Parent_Org_ID"]);
drel.Nested = true;
ds.Relations.Add( drel );

System.IO.MemoryStream stream = new System.IO.MemoryStream();
XmlWriter xmlWriter = new XmlTextWriter(stream, System.Text.Encoding.UTF8);

// Shoot the xml into the xmlWriter stream and reset the underlying stream to the beginning
ds.WriteXml(xmlWriter, XmlWriteMode.IgnoreSchema);
stream.Seek(0, System.IO.SeekOrigin.Begin);

// Add xsl param to set the root node = User's Org ID
XsltArgumentList xslArgList = new XsltArgumentList();
xslArgList.AddParam("topOrgId", "", topOrgId.ToString());

XslTransform xslTransform = new XslTransform();
xslTransform.Load(Server.MapPath("~/infragisticsTransform.xslt"));

XPathDocument xpathDoc = new XPathDocument(stream);
XmlReader xmlReader = xslTransform.Transform(xpathDoc, xslArgList, new XmlUrlResolver());

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(xmlReader);

treeControl.ReadXmlDoc(xmlDoc, true, true);

table.Constraints.Clear();
ds.Relations.Remove( drel );
ds.Tables.Remove( table );
ds.Dispose();

}

If you compile, you get a warning about XslTransform being deprecated, and that System.Xml.Xsl.XslCompiledTransform should be used.  I have tried to figure this out on my own, but I'm having trouble figuring out how it comes together.  Any suggestions?

Parents
No Data
Reply
  • 28464
    posted

    I believe the following two discussions can be helpful in this situation:

    Converting c# .net 1.0 sample using xslTransform to xslCompiledTransform in .net 2.0   

    http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=588904&SiteID=1

    Introducing XslCompiledTransform

    http://blogs.msdn.com/xmlteam/articles/Introducing_XslCompiledTransform.aspx

    Hope this helps. 

Children
No Data