<?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()"/>												 			
			<tr>
			  <td width="33%">
				<xsl:value-of select="@Label"/>
			  </td>	
			  <!-- provide a selection option for numeric properties --> 
			  <xsl:if test="@IsNumeric='True'">
				<xsl:if test="@ControlType='TextBox'">			  					
						<td>
						<select>
							<xsl:attribute name="name">
								<xsl:value-of select="$PropertyName"/>
								<xsl:text>criteria</xsl:text>
							</xsl:attribute>
							<option>=</option>
							<option>&gt;</option>
							<option>&lt;</option>										
							<option>&gt;=</option>						
							<option>&lt;=</option>
							<option>&lt;&gt;</option>						
							<option>Is Null</option>
							<option>Is Not Null</option>
						</select>
						</td>
				</xsl:if>
			  </xsl:if>										  
			  <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>
						</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>
						</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"/>
						</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:for-each>		
		</table>
		</form>
	</body>
</xsl:template>
<xsl:template name="SelectionItems" mode="SelectionItems" match="node()">
	<xsl:variable name="defaultValue" select="text()"/>
	<!-- Provide a default value of "" -->
	<Option></Option>		
	<xsl:for-each select="node()/Value">
		<xsl:variable name="ItemValue" select="text()"/>		
		<option>			
			<xsl:if test="$ItemValue=$defaultValue">
				<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="defaultValue" select="text()"/>	
	<xsl:for-each select="node()/Value">
		<xsl:variable name="ItemValue" select="text()"/>		
		<option>			
			<xsl:if test="$ItemValue=$defaultValue">
				<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()"/>			
		<select>
			<xsl:attribute name="name">
				<xsl:value-of select="$PropertyName"/>				
			</xsl:attribute>			
			<option>Yes or No
				<xsl:attribute name="SELECTED">						
				</xsl:attribute>
			</option>
			<option>Yes</option>
			<option>No</option>			
		</select>					
</xsl:template>
</xsl:stylesheet>
