<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xsi="http://www.w3.org/2000/10/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
	<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
	<xsl:include href="DefaultPrint-r101.xsl"/>
	<xsl:param name="printtype" />
	<xsl:variable name="NativePressureUnits">psi</xsl:variable>
	<xsl:variable name="TheSchema" select="document('AcquityELSD-Method-r100.xsd')"></xsl:variable>
	<xsl:template match="WavelengthMode"/>

	<!-- Emit ChannelB only in dual mode -->
	<xsl:template match="ChannelB">
		<xsl:if test="//WavelengthMode = '2' " >
			<xsl:call-template name="Emit"/>
		</xsl:if>
	</xsl:template>
	
	<!-- Don't emit event table if brief or summary report is requested -->
	<xsl:template match="EventTable">
		<xsl:if test="$printtype = 'Full' or $printtype = 'Plain Text'">
			<xsl:call-template name="Emit"/>
		</xsl:if>
	</xsl:template>

	<!-- Customize text for boolean On/Off at end of FieldList -->
	<xsl:template match="Lamp">
		<xsl:call-template name="Emit-Field-Value-Prompt">
			<xsl:with-param name="InputVar" select="name()"/>
			<xsl:with-param name="InputType">String</xsl:with-param>
			<xsl:with-param name="InputPrecision">0</xsl:with-param>
			<xsl:with-param name="InputValue">
				<xsl:choose>
					<xsl:when test=". = 'true'">On</xsl:when>
					<xsl:otherwise>Off</xsl:otherwise>
				</xsl:choose>
			</xsl:with-param>
			<xsl:with-param name="InputPrompt">Lamp</xsl:with-param>
			<xsl:with-param name="InputUnits">None</xsl:with-param>
		</xsl:call-template>

		<xsl:text disable-output-escaping="yes">
			&lt;/FieldList&gt;
		</xsl:text>
	</xsl:template>

	<!-- Customize output of WavelengthMode -->
	<xsl:template match="WavelengthMode">
		<xsl:call-template name="Emit-Field-Value-Prompt">
			<xsl:with-param name="InputVar" select="name()"/>
			<xsl:with-param name="InputType">String</xsl:with-param>
			<xsl:with-param name="InputPrecision">0</xsl:with-param>
			<xsl:with-param name="InputValue">
				<xsl:choose>
					<xsl:when test=". = '1'">Single Wavelength</xsl:when>
					<xsl:when test=". = '2'">Dual Wavelength</xsl:when>
					<xsl:otherwise>None</xsl:otherwise>
				</xsl:choose>
			</xsl:with-param>
			<xsl:with-param name="InputPrompt">Mode</xsl:with-param>
			<xsl:with-param name="InputUnits">None</xsl:with-param>
		</xsl:call-template>
	</xsl:template>
	
	<!-- Do not expose filter type since Hamming is always used -->
	<xsl:template match="FilterType">
	</xsl:template>
	
	<!-- Expose ratio minimum only if ratio data mode is used -->
	<xsl:template match="RatioMinimum">
		<xsl:if test="//WavelengthMode = '2' and ../DataMode = 'Ratio A/B'">
			<xsl:call-template name="Emit"/>
		</xsl:if>
	</xsl:template>
	
	<!-- Customize text for boolean Yes/No before end of FieldList -->
	<xsl:template match="AutoZeroInjectStart | RunEvents | ChartMarkEnable">
		<xsl:call-template name="Emit-Field-Value-Prompt">
			<xsl:with-param name="InputVar" select="name()"/>
			<xsl:with-param name="InputType">String</xsl:with-param>
			<xsl:with-param name="InputPrecision">0</xsl:with-param>
			<xsl:with-param name="InputValue">
				<xsl:choose>
					<xsl:when test=". = 'true'">Yes</xsl:when>
					<xsl:otherwise>No</xsl:otherwise>
				</xsl:choose>
			</xsl:with-param>
			<xsl:with-param name="InputPrompt">None</xsl:with-param>
			<xsl:with-param name="InputUnits">None</xsl:with-param>
		</xsl:call-template>
	</xsl:template>

	<!-- Exclude absorbance offset from output -->
	<xsl:template match="AbsorbanceOffset">
	</xsl:template>

	<!-- Exclude autozero event or key  from output -->
	<xsl:template match="AutoZeroEventOrKey">
	</xsl:template>

	<!-- Exclude analog A out from Brief -->
	<xsl:template match="AnalogA">
		<xsl:if test="$printtype != 'Brief'">
			<xsl:call-template name="Emit"/>
		</xsl:if>
	</xsl:template>
	
	<!-- Exclude analog B out from Brief or when single wavelength mode -->
	<xsl:template match="AnalogB">
		<xsl:if test="$printtype != 'Brief' and //WavelengthMode = '2' ">
			<xsl:call-template name="Emit"/>
		</xsl:if>
	</xsl:template>
	
	<!-- Exclude threshold A unless printtype is Full and threshold is enabled -->
	<xsl:template match="ThresholdA">
		<xsl:if test="($printtype = 'Full' or $printtype = 'Plain Text') and ./Enable = 'true'">
			<xsl:call-template name="Emit"/>
		</xsl:if>
	</xsl:template>

	<!-- Exclude threshold B unless printtype is Full and in dual wavelength mode and threshold is enabled -->
	<xsl:template match="ThresholdB">
		<xsl:if test="($printtype = 'Full' or $printtype = 'Plain Text') and //WavelengthMode = '2' and ./Enable = 'true'">
			<xsl:call-template name="Emit"/>
		</xsl:if>
	</xsl:template>
	
	<!-- Exclude 'Enable' from threshold output -->
	<xsl:template match="ThresholdA/Enable | ThresholdB/Enable">
	</xsl:template>
	
	<!-- Exclude ratio min and max from analog unless data mode is ratio -->
	<xsl:template match="AnalogA/RatioMinimum | AnalogA/RatioMaximum">
		<xsl:if test="//ChannelA/DataMode = 'Ratio A/B'">
			<xsl:call-template name="Emit"/>
		</xsl:if>
	</xsl:template>

	<xsl:template match="AnalogB/RatioMinimum | AnalogB/RatioMaximum">
		<xsl:if test="//ChannelB/DataMode = 'Ratio A/B'">
			<xsl:call-template name="Emit"/>
		</xsl:if>
	</xsl:template>
	
	<xsl:template match="AcquityELSDMethod">
		<xsl:element name="AcquityELSDMethod">
			<xsl:apply-templates/>
		</xsl:element>
	</xsl:template>

	<!--
		*************************************************************************************************************************
		Emit-Field-Value
		Generate the output for a single parameter in the method, substituting the supplied value string
		*************************************************************************************************************************
	-->

	<xsl:template name="Emit-Field-Value-Prompt">
		<xsl:param name="InputVar"/>
		<xsl:param name="InputType"/>
		<xsl:param name="InputPrecision"/>
		<xsl:param name="InputValue" />
		<xsl:param name="InputPrompt" />
		<xsl:param name="InputUnits" />

		<!-- Get the variable name (prompt) for output; default to the element name if no Prompt property is defined -->
		<xsl:variable name="PromptProperty">
			<xsl:choose>
				<xsl:when test="$InputPrompt='None'">
					<xsl:value-of  select="$TheSchema//xsd:element[@name=$InputVar]//xsd:has-property[@name='Prompt']/@value"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="$InputPrompt"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>
	
		<xsl:variable name="Prompt">
			<xsl:choose>
				<xsl:when test="string-length($PromptProperty) > 0">
					<xsl:value-of select="$PromptProperty"/>
				</xsl:when>
				<xsl:otherwise>
					<xsl:value-of select="name()"/>
				</xsl:otherwise>
			</xsl:choose>
		</xsl:variable>

		<xsl:element name="Field">

			<xsl:attribute name="name">
				<xsl:value-of select="$Prompt"/>
			</xsl:attribute>
				
			<xsl:attribute name="type">
				<xsl:value-of select="$InputType"/>
			</xsl:attribute>

			<xsl:if test="$InputType='Float'">
				<xsl:attribute name="precision">
					<xsl:value-of select="$InputPrecision" />
				</xsl:attribute>
			</xsl:if>

			<!-- Get the units descriptor and output it only if found -->
			<xsl:variable name="Units">
				<xsl:choose>
					<xsl:when test="$InputUnits='None'">
						<xsl:value-of select="$TheSchema//xsd:element[@name=$InputVar]//xsd:has-property[@name='Units']/@value"/>
					</xsl:when>
					<xsl:otherwise>
						<xsl:value-of select="$InputUnits"/>
					</xsl:otherwise>
				</xsl:choose>
			</xsl:variable>
			<xsl:if test="string-length($Units) > 0">
				<xsl:attribute name="units">
					<xsl:choose>
						<xsl:when test="$Units=$NativePressureUnits">
							<xsl:value-of select="$CustomPressureUnits"/>
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="$Units"/>
						</xsl:otherwise>
					</xsl:choose>
				</xsl:attribute>
			</xsl:if>
				
			<xsl:value-of select="$InputValue"/>
			
		</xsl:element>

	</xsl:template>

</xsl:stylesheet>
	
