Click here to Skip to main content
13,054,329 members (69,820 online)
Click here to Skip to main content
Articles » Languages » XML » General » Downloads


136 bookmarked
Posted 15 Oct 2004

Generate dynamic ASP.NET pages by using XML and XSLT

, 15 Oct 2004
Generates dynamic forms by transforming XML into XSL file.
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="" xmlns:asp="remove">
	<xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes"></xsl:output>
	<xsl:template match="/">		
		<xsl:param name="pageid"/>
		<!-- start form page -->
		<table cellpadding="0" cellspacing="5">
			<!-- set title of the current page -->
				<td colspan="3" align="center" style="font-size:25px">
					<xsl:value-of select="FORM/PAGES/PAGE[@id=$pageid]/@title" />
			<tr><td colspan="3" style="height:20px"></td></tr>
			<!-- iterate through page fields -->
			<xsl:for-each select="FORM/PAGES/PAGE[@id=$pageid]/FIELDS/FIELD">			
					<xsl:element name="tr">	
						<xsl:attribute name="id">TR_<xsl:value-of select="PROPERTIES/PROPERTY[@name='ID']"></xsl:value-of></xsl:attribute>
						<!-- hide the row -->
						<xsl:if test="@display='none'">
							<xsl:attribute name="style">display:none;</xsl:attribute>	
							<!-- html control -->
							<xsl:when test="@type='HTML'">
								<td colspan="3">
									&lt;!-- #include file="<xsl:value-of select="@src"></xsl:value-of>" --&gt;
							<!-- other controls -->		
								<!-- field label column -->
								<td valign="top">
									<xsl:value-of select="@label" />
								<!-- field column -->
									<!-- field element -->
									<xsl:element name="asp:{@type}">
										<xsl:attribute name="runat">server</xsl:attribute>
										<xsl:for-each select="./PROPERTIES/PROPERTY">
											<xsl:attribute name="{@name}"><xsl:value-of select="current()"></xsl:value-of></xsl:attribute>
										<xsl:for-each select="./LISTITEMS/LISTITEM">
											<asp:ListItem value="{@value}"><xsl:value-of select="current()"></xsl:value-of></asp:ListItem>
								<!-- validation message column -->					
									<xsl:if test="@required='true'">
										<asp:RequiredFieldValidator ErrorMessage="Required" runat="server" ControlToValidate="{PROPERTIES/PROPERTY[@name='ID']}" />
									<xsl:if test="@validation='Date'">
										<asp:CompareValidator ErrorMessage="Dates Only" runat="server" Operator="DataTypeCheck" Type="Date" ControlToValidate="{PROPERTIES/PROPERTY[@name='ID']}" />
									<xsl:if test="@validation='Number'">
										<asp:CompareValidator ErrorMessage="Numbers Only" runat="server" Operator="DataTypeCheck" Type="Integer" ControlToValidate="{PROPERTIES/PROPERTY[@name='ID']}" />
									<xsl:if test="@validation='Currency'">
										<asp:CompareValidator ErrorMessage="Currency Only" runat="server" Operator="DataTypeCheck" Type="Currency" ControlToValidate="{PROPERTIES/PROPERTY[@name='ID']}" />



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...

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170713.1 | Last Updated 15 Oct 2004
Article Copyright 2004 by rafael_p
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid