XslTransform.Transform 方法将结果输出到字符串里有2中办法:
通过System.IO.MemoryStream类来实现。
通过System.Text.StringBuilder类来实现。
下面是具体的实现方法:
System.Xml.Xsl.XslTransform RssXslt = new System.Xml.Xsl.XslTransform();
System.Xml.XmlDocument RssXml = new System.Xml.XmlDocument();
RssXslt.Load(Server.MapPath("RssReader.xslt"));
RssXml.Load(Server.MapPath("Rss.xml"));
System.IO.MemoryStream t = new System.IO.MemoryStream();
RssXslt.Transform(RssXml,null,t,null);
string resultString = System.Text.UTF8Encoding.UTF8.GetString(t.ToArray());
Response.Write(resultString);
System.Xml.Xsl.XslTransform RssXslt = new System.Xml.Xsl.XslTransform();
System.Xml.XmlDocument RssXml = new System.Xml.XmlDocument();
RssXslt.Load(Server.MapPath("RssReader.xslt"));
RssXml.Load(Server.MapPath("Rss.xml"));
System.Text.StringBuilder t = new System.Text.StringBuilder();
RssXslt.Transform(RssXml,null,new System.IO.StringWriter(t),null);
string resultString = t.ToString();
Response.Write(resultString);
查看本文来源