<?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:variable name="NativePressureUnits">psi</xsl:variable>
	<xsl:variable name="TheSchema" select="document('AcquityELSD-report-r100.xsd')"/>
	<xsl:template match="/*">
		<xsl:element name="AcquityELSDReport">
			<xsl:apply-templates/>
		</xsl:element>
	</xsl:template>
  
  <xsl:template match="GainChanged">
    <xsl:text disable-output-escaping="yes">
					&lt;/FieldList&gt;
		</xsl:text>
  </xsl:template>
  
  <xsl:template match="Messages">
		<xsl:if test="count(child::*) > 0">
			<xsl:element name="FieldList">
				<xsl:element name="Title">Messages</xsl:element>
				<xsl:apply-templates/>
			</xsl:element>
		</xsl:if>
	</xsl:template>
	<xsl:template match="Message">
		<xsl:element name="Field">
			<xsl:attribute name="name">
				<xsl:value-of select="position()"/>
				<xsl:text>. </xsl:text>
			</xsl:attribute>
			<xsl:attribute name="type">String</xsl:attribute>
			<xsl:value-of select="."/>
		</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>
