views:

35

answers:

1

Hello, I'm trying to build an executable which applies XSLT transforms onto a large number XML files. Now my problem is that I'd like to include/refer to the XSLT file stored with my C# VS 2010 solution, so that when I repackage this for another machine, I don't have to copy across the XSLT files. Is this possible?

string xslFile = "C:\template.xslt";
string xmlFile = "C:\\file00324234.xml";
string htmlFile = "C:\\output.htm";

XslCompiledTransform transform = new XslCompiledTransform();
transform.Load(xslFile);
transform.Transform(xmlFile, htmlFile);
+6  A: 

You can include the XSLT as an Embedded Resource into your assembly as described here:

How to embed an XSLT file in a .NET project to be included in the output .exe?

Once embedded, you can use the transform as follows:

using(Stream stream = Assembly.GetExecutingAssembly()
    .GetManifestResourceStream("YourAssemblyName.filename.xslt"))
{
    using (XmlReader reader = XmlReader.Create(stream))
    {
        XslCompiledTransform transform = new XslCompiledTransform ();
        transform.Load(reader);
        // use the XslTransform object
    }
}
0xA3
+1 for the precise answer.
Dimitre Novatchev
Thank you, that helped a lot. There was me thinking the answer wasn't out there.
wonea