Click here to Skip to main content
12,072,067 members (61,547 online)
Click here to Skip to main content
Articles » Languages » XML » General » Downloads


136 bookmarked

Generate dynamic ASP.NET pages by using XML and XSLT

, 15 Oct 2004
Generates dynamic forms by transforming XML into XSL file.
using System;
using System.Data;
using System.Collections;
using System.IO;
using System.Reflection;
using System.Xml;
using System.Xml.Xsl;
using System.Xml.XPath;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace PubsWeb.XmlTransform
	/// <summary>
	/// Summary description for XmlXslTransforer.
	/// </summary>
	public class XmlXslTransforer
		private readonly string XslFile = @"C:\inetpub\wwwroot\pubsweb\xmltransform\default.xslt";
		private readonly string XmlFile = @"C:\inetpub\wwwroot\pubsweb\xmltransform\cx.config";

		public System.Web.UI.WebControls.Panel ControlHolder;

		public XmlXslTransforer()
			// TODO: Add constructor logic here

		public void TransformFields(string pageId)
			 * Transform aspx page with fields from xml file
			 * Get transform result as a string
			 * Parse controls into a parent control holder

			XmlDocument xdoc = new XmlDocument();

			// load xslt to do transformation
			XslTransform xsl = new XslTransform();

			// load xslt arguments to load specific page from xml file
			// this can be used if you have multiple pages in your xml file and you loading them one at a time
			XsltArgumentList xslarg = new XsltArgumentList();
			xslarg.AddParam("pageid", "", pageId);

			// get transformed results
			StringWriter sw = new StringWriter();
			xsl.Transform(xdoc, xslarg, sw);
			string result = sw.ToString().Replace("xmlns:asp=\"remove\"","").Replace("&lt;","<").Replace("&gt;",">");

			// free up the memory of objects that are not used anymore

			// parse the controls and add it to the page
			Control ctrl = ControlHolder.Page.ParseControl(result);

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.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Web Developer
United States United States
I am Microsoft Certified in .NET
I have over seven-year experience with client-server application development (full project lifecycle) on Windows platforms.
I've focused on creating middle tier, web application development, GUI development, custom data management software, and database programming.

You may also be interested in...

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.160208.1 | Last Updated 15 Oct 2004
Article Copyright 2004 by rafael_p
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid