Click here to Skip to main content
15,891,951 members
Articles / Productivity Apps and Services / Microsoft Office

Document and Code Generation by LINQ and XSL

Rate me:
Please Sign up or sign in to vote.
3.87/5 (8 votes)
3 Aug 2008CPOL15 min read 31.8K   340   43  
An article on how to generate source code as well as populate Excel Spreadsheets.
using System;
using System.IO;
using System.Xml;
using System.Xml.XPath;
using System.Xml.Xsl;

namespace CallExternalDll
{
	public class Program
	{
		static void Main()
		{
			const int length = 4;


			// Load the data
			MemoryStream ms = new MemoryStream();
			StreamWriter sssw = new StreamWriter(ms);
			sssw.Write("<?xml version=\"1.0\" encoding=\"utf-8\"?><data>" + length + "</data>");
			sssw.Flush();

			ms.Position = 0;
			XPathDocument doc = new XPathDocument(ms);

			// Output to console using XmlTextWriter
			XmlTextWriter writer = new XmlTextWriter(Console.Out);

			// Enable scripting
			XsltSettings settings = new XsltSettings(true, true);

			// Create the XslTransform
			XslCompiledTransform xslt = new XslCompiledTransform();
			xslt.Load(@"..\..\Transform.xslt", settings, null);

			// Transform the data with the XSLT stylesheet
			xslt.Transform(doc.CreateNavigator(), writer);
			writer.Close();

			Console.WriteLine("\n\nPress Enter To Continue...");
			Console.ReadLine();
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Senior) Webbert Solutions
United States United States
Dave is an independent consultant working in a variety of industries utilizing Microsoft .NET technologies.

Comments and Discussions