Hello:
I have some xml and xsl in string, "not in file". I want to transform the
xml with xsl and the result I want in string (but in xml format). I read
this sample :
public class Sample
{
private const String filename = "mydata.xml";
private const String stylesheet = "myStyleSheet.xsl";
public static void Main()
{
XslTransform xslt = new XslTransform();
xslt.Load(stylesheet);
XPathDocument xpathdocument = new
XPathDocument(filename);
XmlTextWriter writer = new XmlTextWriter(Console.Out);
writer.Formatting=Formatting.Indented;
xslt.Transform(xpathdocument, null, writer, null);
}
And read the class help, but I can found my soluction (maybe I don't so
wise).
Please Help me.
Best regards.
Owen.
Owen - 28 May 2004 23:21 GMT
I found myselft, thanks any way.
public string TransformXml(string aXml, string aXsl)
{
string Result = "";
XmlDocument xml = new XmlDocument();
XmlDocument xsl = new XmlDocument();
xml.LoadXml(aXml);
xsl.LoadXml(aXsl);
//creating xslt
XslTransform xslt = new XslTransform();
xslt.Load(xsl, null,null) ;
//creating stringwriter
StringWriter writer = new System.IO.StringWriter();
//Transform the xml.
xslt.Transform(xml, null, writer, null);
//return string
Result = writer.ToString();
writer.Close();
return Result;
}
> Hello:
>
[quoted text clipped - 25 lines]
> Best regards.
> Owen.