spjewett

spjewett

  • NA
  • 5
  • 0

Embedding XSLTs in a C# Project

Oct 26 2004 10:48 PM
I'm using an XSLT to transform an "in-memory" XML document into an HTML file. The following code performs the transformation without any problems, but it relies on a hard-coded path: XPathNavigator nav = xmlDocRoot.CreateNavigator(); XslTransform xslt = new XslTransform(); xslt.Load("C:/SomeFolder/AnotherFolder/MyXSLT.xslt"); XmlTextWriter htmlPage = new XmlTextWriter(htmlBaseFilename + ".html", null); xslt.Transform(nav, null, htmlPage, null); Replacing the Load method call with the following call works, provided the XSLT is located in the working folder for the app, and it eliminates the need for a hard-coded path: xslt.Load("MyXSLT.xslt"); What I really would like to do is embed the XSLT as a resource in the project (no worries about the file getting deleted or modified by some over zealous user), but I haven't had any luck doing so. Some of Microsoft's documentation describes adding the XSLT file to the project, setting the Build property to Embedded Resource, and calling methods from the "GetManifestResource..." group on the executing assembly, but I can't seem to get it to work. Any ideas on how to embed the XSLT in the project?

Answers (2)