Click here to Skip to main content
Click here to Skip to main content
Articles » Languages » XML » General » Downloads
 
Add your own
alternative version

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="http://www.w3.org/1999/XSL/Transform" 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 -->
			<tr>
				<td colspan="3" align="center" style="font-size:25px">
					<xsl:value-of select="FORM/PAGES/PAGE[@id=$pageid]/@title" />
				</td>
			</tr>
			<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>	
						</xsl:if>
								
						<xsl:choose>
						
							<!-- html control -->
							<xsl:when test="@type='HTML'">
								<td colspan="3">
									&lt;!-- #include file="<xsl:value-of select="@src"></xsl:value-of>" --&gt;
								</td>
							</xsl:when>
						
														
							<!-- other controls -->		
							<xsl:otherwise>							
								
								<!-- field label column -->
								<td valign="top">
									<xsl:value-of select="@label" />
								</td>
								
								<!-- field column -->
								<td>
									
									<!-- 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>
										<xsl:for-each select="./LISTITEMS/LISTITEM">
											<asp:ListItem value="{@value}"><xsl:value-of select="current()"></xsl:value-of></asp:ListItem>
										</xsl:for-each>
									</xsl:element>
									
								</td>	
								
								<!-- validation message column -->					
								<td>
									<xsl:if test="@required='true'">
										<asp:RequiredFieldValidator ErrorMessage="Required" runat="server" ControlToValidate="{PROPERTIES/PROPERTY[@name='ID']}" />
									</xsl:if>
									
									<xsl:if test="@validation='Date'">
										<asp:CompareValidator ErrorMessage="Dates Only" runat="server" Operator="DataTypeCheck" Type="Date" ControlToValidate="{PROPERTIES/PROPERTY[@name='ID']}" />
									</xsl:if>
									
									<xsl:if test="@validation='Number'">
										<asp:CompareValidator ErrorMessage="Numbers Only" runat="server" Operator="DataTypeCheck" Type="Integer" ControlToValidate="{PROPERTIES/PROPERTY[@name='ID']}" />
									</xsl:if>
									
									<xsl:if test="@validation='Currency'">
										<asp:CompareValidator ErrorMessage="Currency Only" runat="server" Operator="DataTypeCheck" Type="Currency" ControlToValidate="{PROPERTIES/PROPERTY[@name='ID']}" />
									</xsl:if>
								</td>						
							</xsl:otherwise>
						
						</xsl:choose>
					</xsl:element>

			</xsl:for-each>	
		</table>	
	</xsl:template>
</xsl:stylesheet>

  

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

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

| Advertise | Privacy | Mobile
Web02 | 2.8.140721.1 | Last Updated 15 Oct 2004
Article Copyright 2004 by rafael_p
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid