Hello,
I need to reorder a Typed DataSet in memory using an Xsl Transform.
Most of the examples use stream which write to the hard disk or xml
file. I want to do this in memory and then write the resulting Typed
Dataset into a Session object which will be reused on multiple
postbacks
and then finally saved when editing is done. Get various problems
depending
on what objects I use, rather than go through each one I will post
what I
have and see if anyone can suggest where to go from here.
Xsl is simple, reordering (this is done becuase onitemupdate of
datagrid I delete element then add a new one. this is because there
are different types of columns and the use="optional" in the xsd file
didn't give me an extra method to remove by column
row.MultipleSel ect.Delete() Anyhow this is peripheral as I am already
down the alley which I hope isn't blind.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output omit-xml-declaration="ye s"/>
<xsl:template match="/*">
<Test>
<xsl:for-each select="/Test/Question">
<xsl:sort select="@id" order="ascendin g" data-type="number"/>
<xsl:copy-of select="."/>
</xsl:for-each>
</Test>
</xsl:template>
</xsl:stylesheet>
Method for reordering DataSet:
try
{
XmlDataDocument xmlDoc = new XmlDataDocument (ds);
XslTransform xslTran = new XslTransform();
xslTran.Load(Se rver.MapPath("Q uestionSort.xsl t"));
System.IO.Memor yStream s = new System.IO.Memor yStream();
System.Xml.XmlT extWriter w = new XmlTextWriter( s,
System.Text.Enc oding.Default );
xslTran.Transfo rm(xmlDoc, (XsltArgumentLi st)null,w,(XmlR esolver)null);
s.Position = 0; //reset position of the in-memory stream.
StreamReader r = new StreamReader(s) ;
Test dsnew = new Test();
dsnew.ReadXml( r.ReadToEnd() );
//this method saves to session object
setDataSet(Sess ionTestName, dsnew);
}
catch (Exception ex)
{
ex = ex;
}
Thanks,
matt