Groups | Blog | Home
all groups > dotnet xml > may 2004 >

dotnet xml : string XML transform


Owen
5/28/2004 11:46:55 AM
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
5/28/2004 5:21:08 PM
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;
}

[quoted text, click to view]

AddThis Social Bookmark Button