Groups | Blog | Home
all groups > dotnet xml > january 2005 >

dotnet xml : XSLT Dataset - need help by transform


Matthias Marx
1/21/2005 10:44:27 AM
Hi,



May some one could help me.

I want to transform data, coming from SQL Server and loaded to a dataset
wiuth xslt.

After that, I want convert it by a xslt style sheet, and store it back or in
a new dataset.



SqlXmlAdapter ad = new SqlXmlAdapter(cmd);

ad.Fill(dsXML);



XslTransform tf = new XstTransform();

tf.Load( @"..\..\MapServices.xsl" );

DataSet ds = new DataSet();



ds.ReadXml(tf.Transform(###What do need here###);



There is no output file or input file, is just in memory a string or a
dataset.



Thank you



Matthias



Derek Harmon
1/21/2005 10:30:58 PM
[quoted text, click to view]

XslTransform( ) returns void, so it needs to be on a separate line
from the ReadXml( ) call. One solution would use the StringReader
and StringWriter classes from the System.IO namespace, like this:

StringWriter sw = new StringWriter( );
tf.Transform( new XmlDataDocument( dsXML), null, new XmlTextWriter( sw));
ds.ReadXml( new StringReader( sw.ToString( )));


Derek Harmon

Oleg Tkachenko [MVP]
1/22/2005 5:44:41 PM
[quoted text, click to view]

Yes, but this requires an interim string buffer and
serializing/reparsing of the transformation result. Actually one can
avoid both using XslTransform.Transform() methods, which return
XmlReader. Then it's just

ds.ReadXml(tf.Transform(new XmlDataDocument(dsXML), null));

--
Oleg Tkachenko [XML MVP, MCP]
Derek Harmon
1/28/2005 10:48:06 PM
[quoted text, click to view]

I stand corrected, there are in fact two overloads of Transform( ) in
1.0 which do return an XmlReader. My mistake, I hadn't noticed them
and took for granted all of its overloads returned void. Clearly, the
overload returning an XmlReader directly would perform much better. :-)


Derek Harmon

AddThis Social Bookmark Button