<xsl:stylesheet version="1.0"
			xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
			xmlns:d="http://schemas.microsoft.com/client/2009/11" 
			xmlns:a="http://schemas.microsoft.com/office/accessservices/2009/11/forms" 
			xmlns:x="http://schemas.microsoft.com/winfx/2009/04/xaml"
			xmlns:SharePoint="Microsoft.SharePoint.WebControls"
			xmlns:asp="http://schemas.microsoft.com/ASPNET/20"
			xmlns:Acc="Microsoft.Office.Access.Server.UI"
			exclude-result-prefixes="xsl d a x">
<xsl:output method="xml" indent="no"/>
<xsl:param name="XmlDefinition" />
<xsl:param name="Assembly" />
<xsl:param name="PageSize" />
<xsl:param name="NavigationButtons" />
<xsl:param name="SuiBottomControlInfoId" />
<xsl:variable name="Rows" select="/dsQueryResponse/NewDataSet/Row"/>
<xsl:template match="/">
	<xsl:text disable-output-escaping="yes"><![CDATA[<]]></xsl:text>
	<xsl:text disable-output-escaping="yes"><![CDATA[%@ Register tagprefix="Acc" namespace="Microsoft.Office.Access.Server.UI" assembly="]]></xsl:text>
	<xsl:value-of select="$Assembly"/>
	<xsl:text disable-output-escaping="yes"><![CDATA[" %>]]></xsl:text>
	<Acc:AccessBootstrap FormType="Form" runat="server"/>
	<xsl:apply-templates  mode="Form" select="$XmlDefinition" />
</xsl:template>
<xsl:template mode="Form" match="a:Form">
	<xsl:variable name="Node" select="."/>
	<xsl:variable name="AlternateBackgroundStyle" select="@AlternateBackground"/>
	<div id="FormXML_Form">
	<xsl:attribute name="class">frm-dft <xsl:if test="@Style != ''"><xsl:value-of select="@Style"/></xsl:if></xsl:attribute>
	<xsl:apply-templates  mode="size" select="." />
	<!-- Header -->
	<xsl:apply-templates mode="Section" select="a:Form.Header/a:Section"/>
	<xsl:apply-templates mode="Records" select="a:Form.Detail/d:DataTemplate">
		<xsl:with-param name="Node" select="$Node"/>
		<xsl:with-param name="Pos" select="0"/>
		<xsl:with-param name="AlternateBackgroundStyle" select="$AlternateBackgroundStyle"/>
	</xsl:apply-templates>
	<!-- Footer -->
	<xsl:apply-templates mode="Section" select="a:Form.Footer/a:Section"/>
	<!-- PageInfo -->
	<xsl:if test="$NavigationButtons='TRUE'">
		<xsl:call-template name="InsertPageInfo">
			<xsl:with-param name="ControlInfoId"><xsl:value-of select="$SuiBottomControlInfoId"/></xsl:with-param>
			<xsl:with-param name="PageSize"><xsl:value-of select="$PageSize"/></xsl:with-param>
		</xsl:call-template>
	</xsl:if>
	</div>
</xsl:template>
<xsl:template mode="Records" match="d:DataTemplate">
	<xsl:param name="Node" />
	<xsl:param name="Pos" />
	<xsl:param name="AlternateBackgroundStyle" />
	<xsl:if test="$Pos &lt; $PageSize">
		<div>
			<xsl:attribute name="name">Record<xsl:value-of select="$Pos"/></xsl:attribute>
			<xsl:if test="$Pos &gt;= count($Rows) and $Pos &gt; 0">
				<xsl:attribute name="style"><xsl:text>display:none;visibility:hidden;</xsl:text></xsl:attribute>
			</xsl:if>
			<xsl:if test="$Pos mod 2 = 1 and $AlternateBackgroundStyle != ''">
				<xsl:attribute name="class">
					<xsl:value-of select="$AlternateBackgroundStyle"/>
				</xsl:attribute>
			</xsl:if>
			<!-- Sections -->
			<xsl:apply-templates mode="Section" select="a:Section">
				<xsl:with-param name="Pos" select="$Pos"/>
				<xsl:with-param name="AlternateBackgroundStyle" select="$AlternateBackgroundStyle"/>
			</xsl:apply-templates>
			<xsl:apply-templates mode="Control" select="$Node/a:Field">
				<xsl:with-param name="Pos" select="$Pos"/>
			</xsl:apply-templates>
		</div>
		<xsl:apply-templates mode="Records" select=".">
			<xsl:with-param name="Node" select="$Node"/>
			<xsl:with-param name="Pos" select="$Pos + 1"/>
			<xsl:with-param name="AlternateBackgroundStyle" select="$AlternateBackgroundStyle"/>
		</xsl:apply-templates>
	</xsl:if>
</xsl:template>
<xsl:template mode="Control" match="a:TabControl">
	<xsl:param name="Pos" />
	<xsl:variable name="Visibility" select="@Visibility"/>
	<xsl:variable name="Style" select="@Style"/>
	<xsl:variable name="StyleSelected" select="@StyleSelected"/>
	<div class="acc-tab-cnt">
		<xsl:apply-templates  mode="size" select="." />
		<Acc:accessformfield runat="server" ControlInfoId="{@x:Name}" ControlType="TabControl">
			<xsl:if test="$Pos != ''">
				<xsl:attribute name="RowId">
					<xsl:value-of select="$Pos"/>
				</xsl:attribute>
			</xsl:if>
			<!-- Style applies to individual tab buttons -->
			<xsl:apply-templates select="@*[name() != 'Style']" mode="copy"/>
			<!-- Individual tab buttons -->
			<xsl:for-each select="a:TabItem">
				<Acc:accessformfield runat="server" ControlInfoId="{@x:Name}" ControlType="TabButton">
					<xsl:apply-templates  mode="controlSize" select="." />
					<!-- use parent's style -->
					<xsl:attribute name="class">
						<xsl:text>all-dft </xsl:text>
						<xsl:value-of select="$Style"/>
						<xsl:text> </xsl:text>
						<xsl:value-of select="@Style"/>
					</xsl:attribute>
					<!-- SelectedStyle applies to tab pages and selected buttons, Style is applied above -->
					<xsl:apply-templates select="@*[name() != 'Style']" mode="copy" />
				</Acc:accessformfield>
			</xsl:for-each>
		</Acc:accessformfield>
		<!-- Don't change this ID.  We look for it in %accsrv%\client\controls\tab.cs. -->
		<div id="TabsContent">
			<xsl:if test="$Visibility='Hidden'"><xsl:attribute name="style">visibility:hidden;</xsl:attribute></xsl:if>
			<xsl:for-each select="a:TabItem">
				<Acc:accessformfield runat="server" ControlInfoId="{@x:Name}" ControlType="TabItem">
					<xsl:if test="$Pos != ''">
						<xsl:attribute name="RowId">
							<xsl:value-of select="$Pos"/>
						</xsl:attribute>
					</xsl:if>
					<!-- tabcontrol's SelectedStyle applies to tab pages, o14.326768 -->
					<xsl:attribute name="class"><xsl:value-of select="$Style"/><xsl:text> </xsl:text><xsl:value-of select="$StyleSelected"/></xsl:attribute>
					<xsl:apply-templates select="@*[name() != 'Style']" mode="copy">
						<xsl:with-param name="Pos" select="$Pos"/>
					</xsl:apply-templates>
					<xsl:attribute name="style">display:none;</xsl:attribute>
					<xsl:if test="d:Grid">
						<fieldset>
							<xsl:attribute name="class"><xsl:text>acc-sec</xsl:text></xsl:attribute>
							<xsl:apply-templates mode="Grid" select="d:Grid" >
								<xsl:with-param name="Pos" select="$Pos"/>
							</xsl:apply-templates>
						</fieldset>
					</xsl:if>
				</Acc:accessformfield>
			</xsl:for-each>
		</div>
	</div>
</xsl:template>
<xsl:template mode="Section" match="a:Section">
	<xsl:param name="Pos" />
	<xsl:param name="AlternateBackgroundStyle" />
	<fieldset>
		<xsl:choose>
			<xsl:when test="d:Grid">
				<xsl:attribute name="class"><xsl:text>acc-sec </xsl:text><xsl:if test="@Style != ''"><xsl:value-of select="@Style"/></xsl:if></xsl:attribute>
				<xsl:apply-templates mode="Grid" select="d:Grid" >
					<xsl:with-param name="Pos" select="$Pos"/>
					<xsl:with-param name="AlternateBackgroundStyle" select="$AlternateBackgroundStyle"/>
				</xsl:apply-templates>
			</xsl:when>
			<xsl:otherwise>
				<xsl:attribute name="class"><xsl:text>acc-empty-sec </xsl:text><xsl:if test="@Style != ''"><xsl:value-of select="@Style"/></xsl:if></xsl:attribute>
				<!-- This is to ensure that <fieldset> closing tag is written separately (required in html, o14.329696) -->
				<xsl:if test="not(d:Grid)"><xsl:text> </xsl:text></xsl:if>
			</xsl:otherwise>
		</xsl:choose>
	</fieldset>
</xsl:template>
<xsl:template mode="Grid" match="d:Grid">
	<xsl:param name="Pos" />
	<xsl:param name="AlternateBackgroundStyle" />
	<table cellSpacing="0" cellPadding="0">
		<xsl:attribute name="class">
			<xsl:text>acc-tbl </xsl:text>
			<xsl:if test="$Pos mod 2 = 1 and $AlternateBackgroundStyle != ''">
				<xsl:value-of select="$AlternateBackgroundStyle"/>
			</xsl:if>
		</xsl:attribute>
		<xsl:apply-templates  mode="calculate-width" select=".">
			<xsl:with-param name="Width" select="0"/>
			<xsl:with-param name="Pos" select="1"/>
		</xsl:apply-templates>
		<tbody>
			<xsl:apply-templates  mode="cols" select="." />
			<xsl:apply-templates mode="Row" select="d:Grid.RowDefinitions/d:RowDefinition">
				<xsl:with-param name="Pos" select="$Pos"/>
			</xsl:apply-templates>
		</tbody>
	</table>
</xsl:template>
<xsl:template mode="Row" match="d:RowDefinition">
	<xsl:param name="Pos" />
	<tr>
		<xsl:choose>
			<xsl:when test="not(@Height)">
				<xsl:attribute name="stretch">1</xsl:attribute>
				<td style="width:1px;"><xsl:text> </xsl:text></td>
			</xsl:when>
			<xsl:otherwise>
				<td>
					<xsl:attribute name="style">height:<xsl:value-of select="@Height"/>px;width:1px;</xsl:attribute>
					<xsl:text> </xsl:text>
				</td>
			</xsl:otherwise>
		</xsl:choose>
		<xsl:apply-templates mode="Column" select="../../d:Grid.ColumnDefinitions/d:ColumnDefinition">
			<xsl:with-param name="Pos" select="$Pos"/>
			<xsl:with-param name="RowPosition" select="position()"/>
		</xsl:apply-templates>
	</tr>
</xsl:template>
<xsl:template mode="Column" match="d:ColumnDefinition">
	<xsl:param name="Pos" />
	<xsl:param name="RowPosition" />
	<xsl:variable name="ColPosition" select="position()"/>
	<xsl:apply-templates mode="Cell" select="../../*[@Grid.Column+1=$ColPosition and @Grid.Row+1=$RowPosition]">
		<xsl:with-param name="Pos" select="$Pos"/>
	</xsl:apply-templates>
</xsl:template>
<xsl:template mode="Cell" match="d:Border">
	<xsl:param name="Pos" />
	<td>
		<xsl:if test="@Grid.ColumnSpan">
			<xsl:attribute name="colspan"><xsl:value-of select="@Grid.ColumnSpan"/></xsl:attribute>
		</xsl:if>
		<xsl:if test="@Grid.RowSpan">
			<xsl:attribute name="rowspan"><xsl:value-of select="@Grid.RowSpan"/></xsl:attribute>
		</xsl:if>
		<xsl:attribute name="class">
			<xsl:text>td-dft </xsl:text><xsl:if test="@Style != ''"><xsl:value-of select="@Style"/></xsl:if>
		</xsl:attribute>
		<xsl:apply-templates mode="Control" select="*">
			<xsl:with-param name="Pos" select="$Pos"/>
		</xsl:apply-templates>
	</td>
</xsl:template>
<xsl:template mode="Control" match="a:EmptyCell">
	<div>
		<xsl:attribute name="class"><xsl:text>empty </xsl:text><xsl:value-of select="@Style"/></xsl:attribute>
		<xsl:attribute name="style">
			<xsl:if test="@Height != ''">height:<xsl:value-of select="@Height"/>px;</xsl:if>
			<xsl:if test="@Width != ''">width:<xsl:value-of select="@Width"/>px;</xsl:if>
		</xsl:attribute>
		<xsl:text> </xsl:text>
	</div>
</xsl:template>
<xsl:template mode="Control" match="a:NavigationControl">
	<xsl:param name="Pos" />
	<Acc:accessformfield runat="server" ControlInfoId="{@x:Name}" ControlType="NavigationControl">
		<xsl:apply-templates  mode="controlSize" select="." />
		<xsl:if test="$Pos != ''">
			<xsl:attribute name="RowId"><xsl:value-of select="$Pos"/></xsl:attribute>
		</xsl:if>
		<xsl:apply-templates select="@*" mode="copy" />
		<table cellSpacing="0" cellPadding="0" class="acc-tbl-nav">
			<tbody>
				<xsl:choose>
					<xsl:when test="@Span = 'Vertical'">
						<xsl:for-each select="d:Border">
							<tr>
								<xsl:apply-templates mode="Cell" select=".">
									<xsl:with-param name="Pos" select="$Pos"/>
								</xsl:apply-templates>
							</tr>
						</xsl:for-each>
					</xsl:when>
					<xsl:otherwise>
						<tr>
							<xsl:apply-templates mode="Cell" select="*">
								<xsl:with-param name="Pos" select="$Pos"/>
							</xsl:apply-templates>
						</tr>
					</xsl:otherwise>
				</xsl:choose>
			</tbody>
		</table>
	</Acc:accessformfield>
</xsl:template>
<xsl:template mode="Control" match="*">
	<xsl:param name="Pos" />
	<Acc:accessformfield runat="server" ControlInfoId="{@x:Name}">
		<xsl:attribute name="ControlType"><xsl:value-of select="local-name()"/></xsl:attribute>
		<xsl:apply-templates  mode="controlSize" select="." />
		<xsl:if test="$Pos != ''">
			<xsl:attribute name="RowId"><xsl:value-of select="$Pos"/></xsl:attribute>
		</xsl:if>
		<xsl:apply-templates select="@*" mode="copy">
			<xsl:with-param name="Pos" select="$Pos"/>
		</xsl:apply-templates>
	</Acc:accessformfield>
</xsl:template>
<xsl:template match="@*" mode="copy">
	<xsl:attribute name="{local-name()}"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>
<xsl:template match="@ControlSource" mode="copy">
	<xsl:param name="Pos" />
	<xsl:variable name="Value"><xsl:value-of select="."/></xsl:variable>
	<xsl:attribute name="DataValue"><xsl:value-of select="$Rows[$Pos + 1]/@*[name() = $Value]"/></xsl:attribute>
</xsl:template>
<xsl:template match="@Style" mode="copy">
	<xsl:attribute name="class"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>
<xsl:template match="@StyleSelected" mode="copy"/>
<xsl:template match="@x:Name | @TabIndex |@Width | @Height" mode="copy" />
<xsl:template name="InsertPageInfo">
	<xsl:param name="ControlInfoId" />
	<xsl:param name="PageSize" />
	<fieldset class="acc-sec">
		<Acc:accessformfield runat="server" ControlInfoId="{$ControlInfoId}" PageSize="{$PageSize}" ControlType="PageInfo" />
	</fieldset>
</xsl:template>
<xsl:template match="*" mode="size">
	<xsl:if test="@Height != '' or @Width != ''">
		<xsl:attribute name="style">
			<xsl:if test="@Height != ''">height:<xsl:value-of select="@Height"/>px;</xsl:if>
			<xsl:if test="@Width != ''">width:<xsl:value-of select="@Width"/>px;</xsl:if>
		</xsl:attribute>
	</xsl:if>
</xsl:template>
<xsl:template match="*" mode="controlSize">
	<xsl:if test="@Height != ''"><xsl:attribute name="Height_"><xsl:value-of select="@Height"/>px</xsl:attribute></xsl:if>
	<xsl:if test="@Width != ''"><xsl:attribute name="Width_"><xsl:value-of select="@Width"/>px</xsl:attribute></xsl:if>
</xsl:template>
<xsl:template match="d:Grid" mode="cols">
	<tr style="height:1px;">
		<td style="width:1px;"><xsl:text> </xsl:text></td>
		<xsl:for-each select="d:Grid.ColumnDefinitions/d:ColumnDefinition">
			<td class="empty">
				<xsl:choose>
					<xsl:when test="not(@Width)">
						<xsl:attribute name="stretch">1</xsl:attribute>
					</xsl:when>
					<xsl:otherwise>
						<xsl:attribute name="style">width:<xsl:value-of select="@Width"/>px;</xsl:attribute>
					</xsl:otherwise>
				</xsl:choose>
				<div class = "empty">
					<xsl:choose>
						<xsl:when test="not(@Width)">
							<xsl:attribute name="stretch">1</xsl:attribute>
							<xsl:attribute name="style">height:1px;</xsl:attribute>
						</xsl:when>
						<xsl:otherwise>
							<xsl:attribute name="style">width:<xsl:value-of select="@Width"/>px;height:1px;</xsl:attribute>
						</xsl:otherwise>
					</xsl:choose>
					<xsl:text> </xsl:text>
				</div>
			</td>
		</xsl:for-each>
	</tr>
</xsl:template>
<xsl:template match="d:Grid" mode="calculate-width">
	<xsl:param name="Width" />
	<xsl:param name="Pos" />
	<xsl:choose>
		<xsl:when test="$Pos &lt;= count(d:Grid.ColumnDefinitions/d:ColumnDefinition)">
			<xsl:variable name="Node" select="d:Grid.ColumnDefinitions/d:ColumnDefinition[$Pos]"/>
			<xsl:if test="$Node/@Width != ''">
				<xsl:apply-templates mode="calculate-width" select=".">
					<xsl:with-param name="Pos" select="$Pos + 1"/>
					<xsl:with-param name="Width" select="$Width + $Node/@Width"/>
				</xsl:apply-templates>
			</xsl:if>
		</xsl:when>
		<xsl:otherwise>
			<xsl:attribute name="style">width:<xsl:value-of select="$Width"/>px;</xsl:attribute>
		</xsl:otherwise>
	</xsl:choose>
</xsl:template>
</xsl:stylesheet>
