Include XSLT file in executable file

I am trying to create an executable file that applies XSLT transformations to a large number of XML files. Now my problem is that I would like to include / access the XSLT file stored in my C # VS 2010 solution, so when I repackage this for another machine, I do not need to copy the XSLT files. Is it 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);
+5
source share
1 answer

You can include XSLT as an embedded resource in your assembly, as described here:

How to include an XSLT file in a .NET project for inclusion in the output .exe file?

After embedding, you can use the transformation 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
    }
}
+12
source

All Articles