Reputation: 4969
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);
Upvotes: 6
Views: 1740
Reputation: 176169
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
}
}
Upvotes: 13