<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!-- Match the root node of the DOM document -->
<xsl:template match="/">
	<html>
	<!-- Match the document element node by name -->
	<xsl:apply-templates/>
	</html>
</xsl:template>
<xsl:template match="*">
	<head>	
	<title>
		<xsl:value-of select="@Title"/>
	</title>
		<xsl:variable name="submitValue" select="@action"/>
	</head>
	<body bgcolor="#FFFFFF">
	  <h1><xsl:value-of select="@Title"/></h1>
	  <br/>
		<form>
		  <xsl:attribute name="action">
		    <xsl:value-of select="$submitValue"/>
		  </xsl:attribute>
		   <table border="0" width="70%">
		   <xsl:for-each select="*">
			<xsl:variable name="PropertyName" select="name()"/>	
			<!-- do not display System Generated properties -->
			<xsl:if test="@SystemGenerated='False'">
			  <!-- do not display hidden properties -->
			   <xsl:if test="@Access!='Hidden'">							 			
				<tr>
				  <td valign="top" bgcolor="#CDEDFF" width="33%">
					<xsl:value-of select="@Label"/>
					  <!-- if a property is mandatory put an indicator next to the label-->
					  <!-- include a hidden control for a mandatory property -->
					  <xsl:if test="@Mandatory='True'">					
						<font color="RED">
							<xsl:text> *</xsl:text>
						</font>
						<input type='hidden' value='True'>
							<xsl:attribute name="name">
								<xsl:value-of select="$PropertyName"/>
								<xsl:text>Required</xsl:text>
							</xsl:attribute>
						</input>
					  </xsl:if>
				  </td>
				  <td>
					<xsl:choose>
						<xsl:when test="@ControlType='TextBox'">
							<input type="text">
								<xsl:attribute name="name">
									<xsl:value-of select="name()"/>
								</xsl:attribute>
								<xsl:attribute name="value">
									<xsl:value-of select="text()"/>
								</xsl:attribute>
								<xsl:if test="@Access='Read Only'">
									<xsl:attribute name="ONFOCUS">this.blur()</xsl:attribute>
								</xsl:if>
							</input>
						</xsl:when>
						<xsl:when test="@ControlType='PromptForm'">
							<input type="text">
								<xsl:attribute name="name">
									<xsl:value-of select="name()"/>
								</xsl:attribute>
								<xsl:attribute name="value">
									<xsl:value-of select="text()"/>
								</xsl:attribute>
								<xsl:if test="@Access='Read Only'">
							  		<xsl:attribute name="ONFOCUS">this.blur()</xsl:attribute>
								</xsl:if>
							</input>
						</xsl:when>
						<xsl:when test="@ControlType='DatePicker'">
							<input type="text">
								<xsl:attribute name="name">
									<xsl:value-of select="name()"/>
								</xsl:attribute>
								<xsl:attribute name="value">
									<xsl:value-of select="text()"/>
								</xsl:attribute>
								<xsl:if test="@Access='Read Only'">
									<xsl:attribute name="ONFOCUS">this.blur()</xsl:attribute>
								</xsl:if>
							</input>
						</xsl:when>
						<xsl:when test="@ControlType='ComboBox'">
							<select>
								<xsl:attribute name="name">
									<xsl:value-of select="name()"/>
								</xsl:attribute>
								<xsl:call-template name="SelectionItems"/>
								<xsl:if test="@Access='Read Only'">
									<xsl:attribute name="ONFOCUS">this.blur()</xsl:attribute>
								</xsl:if>
							</select>
						</xsl:when>
						<xsl:when test="@ControlType='ListBox'">
							<select>
								<xsl:attribute name="name">
									<xsl:value-of select="name()"/>
								</xsl:attribute>
								<xsl:attribute name="Multiple">
								</xsl:attribute>
							<xsl:call-template name="MultipleItems"/>
							</select>
						</xsl:when>
						<xsl:when test="@ControlType='OptionButton'">
							<xsl:call-template name="RadioItems"/>
						</xsl:when>
						<xsl:when test="@ControlType='CheckBox'">
							<xsl:call-template name="CheckBoxItems"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="text()"/>
						</xsl:otherwise>
					</xsl:choose>
				  </td>
				</tr>
				</xsl:if>
			</xsl:if>
		</xsl:for-each>		
		</table>
		</form>
	</body>
</xsl:template>

<xsl:template name="SelectionItems" mode="SelectionItems" match="node()">
	<xsl:variable name="PropertyValue" select="text()"/>			
	  <xsl:for-each select="node()/Value">		
		<xsl:variable name="ItemValue" select="text()"/>		
		  <option>					
			<xsl:if test="$ItemValue=$PropertyValue">							
				<xsl:attribute name="SELECTED">														
				</xsl:attribute>													
			</xsl:if>			
			<xsl:value-of select="$ItemValue"/>		
		</option>			
	  </xsl:for-each>
</xsl:template>

<xsl:template name="MultipleItems" mode="MultipleItems" match="node()">			
	<xsl:variable name="PropertyValue" select="text()"/>	
	  <xsl:for-each select="node()/Value">
		<xsl:variable name="ItemValue" select="text()"/>		
		  <option>			
			<xsl:if test="$ItemValue=$PropertyValue">
				<xsl:attribute name="SELECTED">																	
				</xsl:attribute>
			</xsl:if>
			<xsl:value-of select="$ItemValue"/>		
		  </option>
	  </xsl:for-each>
</xsl:template>

<xsl:template name="RadioItems" mode="RadioItems" match="node()">
	<xsl:variable name="PropertyValue" select="text()"/>
	<xsl:variable name="PropertyName" select="name()"/>	
	<xsl:for-each select="node()/Value">
		<xsl:variable name="ItemValue" select="text()"/>	
		  <input type="radio">
			<xsl:if test="$ItemValue=$PropertyValue">
				<xsl:attribute name="checked">					
				</xsl:attribute>
			</xsl:if>
			<xsl:attribute name="name">
				<xsl:value-of select="$PropertyName"/>
			</xsl:attribute>
			<xsl:attribute name="value">
				<xsl:value-of select="$ItemValue"/>
			</xsl:attribute>
			<xsl:value-of select="text()"/>
		  </input>
		<!-- put the next option on a new line -->
		<br/>
	</xsl:for-each>
</xsl:template>

<xsl:template name="CheckBoxItems" mode="CheckBoxItems" match="node()">
	<xsl:variable name="PropertyName" select="name()"/>
	<xsl:variable name="PropertyValue" select="text()"/>	
		<input type="Checkbox">			
			<xsl:attribute name="name">
				<xsl:value-of select="$PropertyName"/>
			</xsl:attribute>
			<xsl:if test="$PropertyValue='True'">
				<xsl:attribute name="checked">					
				</xsl:attribute>
			</xsl:if>			
		</input>			
</xsl:template>
</xsl:stylesheet>
