M
Matthew Baskey
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.MultipleSelect.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:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput omit-xml-declaration="yes"/>
<xsl:template match="/*">
<Test>
<xsl:for-each select="/Test/Question">
<xsl:sort select="@id" order="ascending" 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(Server.MapPath("QuestionSort.xslt"));
System.IO.MemoryStream s = new System.IO.MemoryStream();
System.Xml.XmlTextWriter w = new XmlTextWriter( s,
System.Text.Encoding.Default );
xslTran.Transform(xmlDoc, (XsltArgumentList)null,w,(XmlResolver)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(SessionTestName, dsnew);
}
catch (Exception ex)
{
ex = ex;
}
Thanks,
matt
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.MultipleSelect.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:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xslutput omit-xml-declaration="yes"/>
<xsl:template match="/*">
<Test>
<xsl:for-each select="/Test/Question">
<xsl:sort select="@id" order="ascending" 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(Server.MapPath("QuestionSort.xslt"));
System.IO.MemoryStream s = new System.IO.MemoryStream();
System.Xml.XmlTextWriter w = new XmlTextWriter( s,
System.Text.Encoding.Default );
xslTran.Transform(xmlDoc, (XsltArgumentList)null,w,(XmlResolver)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(SessionTestName, dsnew);
}
catch (Exception ex)
{
ex = ex;
}
Thanks,
matt