<!--	
 	Copyright 2006 Intuit Inc. All rights reserved. Unauthorized reproduction
 	is a violation of applicable law. This material contains certain  
 	confidential or proprietary information and trade secrets of Intuit Inc.
-->

<!-- This XSL file transforms QBXML like responses (The responses are not pure 
	 SDK responses since we embed some proprietary elements/attributes in them) into 
	 QBXML like Add and Mod requests. A proprietary <AFXInfo> element is used to embed 
	 any non-SDK Add/Mod request information.
	 Most of the transformation is handled using XSL templates and copying 
	 of elements where necessary.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

  <!-- Fail safe template for matching any query response that we do not support -->
  <xsl:template match="QBXML/QBXMLMsgsRs/*/*"/>

  <!-- Match the top level element AFXChangeList -->
  <xsl:template match="AFXChangeList">
    <xsl:processing-instruction name="qbxml">version="6.0"</xsl:processing-instruction>
    <AFXChangeList>
	  <!-- Apply any template which matches up with the child element of AFXChangeList --> 
      <xsl:apply-templates/>
    </AFXChangeList>
  </xsl:template>

  <xsl:template match="AccountantNote">
    <xsl:copy-of select="..//AccountantNote"/>
  </xsl:template>

  
  <xsl:template match="DividingDate">
    <xsl:copy-of select="..//DividingDate"/>
  </xsl:template>

  <xsl:template match="Path">
    <xsl:copy-of select="..//Path"/>
  </xsl:template>
    
  <!-- Match the element QBXML/QBXMLMsgsRs. There will be one of each of these
  	   elements for every Add and Mod responses. -->
  <xsl:template match="QBXML/QBXMLMsgsRs">
       <xsl:choose>
	    <!-- Do not pass on any NonPosting accounts-->
   		<xsl:when test="AccountQueryRs/AccountRet and (AccountQueryRs/AccountRet/AccountType = 'NonPosting')">
        </xsl:when>
        <xsl:otherwise>
		    <QBXML>
		      <QBXMLMsgsRq onError="continueOnError">
		        	<xsl:apply-templates/>
		      </QBXMLMsgsRq>
		    </QBXML>
        </xsl:otherwise>
      </xsl:choose>
  </xsl:template>

  <xsl:template match="AccountQueryRs/AccountRet">

	    <AccountAddRq>
	      <xsl:attribute name="requestID">
		  	<!-- Get the requestId from the parent AccountAddRs element -->
	        <xsl:value-of select="..//@requestID"/>
	      </xsl:attribute>
	      <AccountAdd>
		    <!-- ListId is not part of the Account Add request but needed while
				 importing accountant changes on the client side. -->
		  	<AFXInfo>	
			  <xsl:copy-of select="ListID"/>
			  <xsl:copy-of select="AccountNumber"/>
			</AFXInfo>
	        <xsl:copy-of select="Name"/>
	        <xsl:copy-of select="IsActive"/>
	        <xsl:copy-of select="ParentRef"/>
	        <xsl:copy-of select="AccountType"/>
	        <xsl:copy-of select="DetailAccountType"/>
	        <xsl:copy-of select="AccountNumber"/>
	        <xsl:copy-of select="BankNumber"/>
	        <xsl:copy-of select="Desc"/>
	      </AccountAdd>
	    </AccountAddRq>
  </xsl:template>

  <xsl:template match="AccountQueryRs/AccountRet[@mod='1']">
    <AccountModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent AccountAddRs element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <AccountMod>
        <AFXInfo>
          <xsl:copy-of select="AccountNumber"/>
        </AFXInfo>
       	<xsl:copy-of select="ListID"/>
        <xsl:copy-of select="EditSequence"/>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
		<xsl:choose>
		  <xsl:when test="ParentRef">
		    <xsl:copy-of select="ParentRef"/>
		  </xsl:when>
          <xsl:otherwise>
            <ParentRef>
			  <ListID></ListID>
            </ParentRef>
          </xsl:otherwise> 
 		</xsl:choose>
        <xsl:copy-of select="AccountType"/>
        <xsl:copy-of select="AccountNumber"/>
        <xsl:copy-of select="BankNumber"/>
        <xsl:copy-of select="Desc"/>
      </AccountMod>
    </AccountModRq>
  </xsl:template>


  <xsl:template match="InvoiceQueryRs/InvoiceRet">
    <InvoiceAddRq>
      <xsl:attribute name="requestID">
		  	<!-- Get the requestId from the parent InvoiceRs element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <InvoiceAdd>
	    <!-- TxnID is not part of the Invoice Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
        <xsl:copy-of select="BalanceRemaining"/>
        <xsl:copy-of select="AppliedAmount"/>
	  	</AFXInfo>
        <xsl:call-template name="CreditMemoInvoiceDetails"/>
        <xsl:apply-templates select="InvoiceLineRet | InvoiceLineGroupRet"/>
        <xsl:call-template name="DiscountSalesTaxLines"/>
      </InvoiceAdd>
    </InvoiceAddRq>
  </xsl:template>

  <!-- Mod responses have a proprietary mod attribute set to 1 in the *Ret element -->
  <xsl:template match="InvoiceQueryRs/InvoiceRet[@mod='1']">
    <xsl:choose>
		<xsl:when test="BalanceRemaining = '0.00' and starts-with(Memo, 'VOID:')">
			<TxnVoidRq>
				<TxnVoidType>Invoice</TxnVoidType>
		        <xsl:copy-of select="TxnID"/>
				<AFXInfo>
       					<InvoiceRet>
				        <xsl:call-template name="CreditMemoInvoiceDetails"/>
				        <xsl:apply-templates select="InvoiceLineRet | InvoiceLineGroupRet"/>
				        <xsl:call-template name="DiscountSalesTaxLines"/>
                <xsl:copy-of select="BalanceRemaining"/>
                <xsl:copy-of select="AppliedAmount"/>
					</InvoiceRet>
				</AFXInfo>
			</TxnVoidRq>
		</xsl:when>
        <xsl:otherwise> 
		    <InvoiceModRq>
		      <xsl:attribute name="requestID">
				  	<!-- Get the requestId from the parent InvoiceRs element -->
		        <xsl:value-of select="..//@requestID"/>      </xsl:attribute>
		      <InvoiceMod>
		        <xsl:copy-of select="TxnID"/>
		        <xsl:copy-of select="EditSequence"/>
		        <xsl:call-template name="CreditMemoInvoiceDetails"/>
		        <xsl:apply-templates select="InvoiceLineRet | InvoiceLineGroupRet">
				  	  <xsl:with-param name="mod" select="1" />
			  	  </xsl:apply-templates>
            <AFXInfo>
              <xsl:copy-of select="BalanceRemaining"/>
              <xsl:copy-of select="AppliedAmount"/>
            </AFXInfo>
		      </InvoiceMod>
		    </InvoiceModRq>
        </xsl:otherwise> 
    </xsl:choose>  	

  </xsl:template>

  <xsl:template match="InvoiceLineRet | InvoiceLineGroupRet">

	<!-- Default the mod param to 0. The mod param is set to 1 only 
		 when invoked while transforming to Mod requests. -->
	<xsl:param name="mod" select="0"/>

 	<!-- Default the InvoiceLineGroupMod param to 0. This param is set to 1 only 
 		 when invoked while transforming InvoiceLineGroupRet query responses. -->
 	<xsl:param name="InvoiceLineGroupMod" select="0"/>

	<!-- We no longer transform InvoiceLineGroupRet aggregates to InvoiceLineGroupAdd/Mod since 
		 the UI allows a lot of flexibility in how the individual line items can be added/
		 modified but the SDK InvoiceLineGroupAdd aggregate does not list all of the line items 
		 in that group.
		 Instead we create an InvoiceLineAdd/InvoiceLineMod(with TxnLineId = -1 for items which have 
		 not been modified which essentially is an InvoiceLineAdd) for each item in the group 
		 and discard the group.
	-->

    <xsl:if test="name(.) = 'InvoiceLineRet'">
       <xsl:choose>
        <xsl:when test="$mod='0'">
	      <InvoiceLineAdd>
	        <xsl:call-template name="ItemLineAddDetails"/>
	      </InvoiceLineAdd>
        </xsl:when>
        <xsl:otherwise>
  	      <InvoiceLineMod>
	        <xsl:call-template name="ItemLineModDetails">
				<xsl:with-param name="ItemGroupLineMod" select="$InvoiceLineGroupMod"/>
			</xsl:call-template>
      	  </InvoiceLineMod>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>

    <xsl:if test="name(.) = 'InvoiceLineGroupRet'">
       <xsl:choose>
        <xsl:when test="$mod='0'">
 	      <xsl:apply-templates select="InvoiceLineRet | InvoiceLineGroupRet"/>
        </xsl:when>
        <xsl:otherwise>
   	        <xsl:apply-templates select="InvoiceLineRet | InvoiceLineGroupRet">
   				<xsl:with-param name="mod" select="1" />
 				<xsl:with-param name="InvoiceLineGroupMod" select="1" />
   			</xsl:apply-templates>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>


  <xsl:template match="CreditMemoQueryRs/CreditMemoRet">
    <CreditMemoAddRq>
      <xsl:attribute name="requestID">
		  	<!-- Get the requestId from the parent CreditMemoRs element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <CreditMemoAdd>
	      <!-- TxnID is not part of the CreditMemoAdd request but needed while
			   importing accountant changes on the client side. -->
	  	  <AFXInfo>
	    	  <xsl:copy-of select="TxnID"/>
	    	  <xsl:copy-of select="TotalAmount"/>
	  	  </AFXInfo>
          <xsl:call-template name="CreditMemoInvoiceDetails"/>
          <xsl:apply-templates select="CreditMemoLineRet | CreditMemoLineGroupRet"/>
          <xsl:call-template name="DiscountSalesTaxLines"/>
      </CreditMemoAdd>
    </CreditMemoAddRq>
  </xsl:template>

  <!-- Mod responses have a proprietary mod attribute set to 1 in the *Ret element -->
  <xsl:template match="CreditMemoQueryRs/CreditMemoRet[@mod='1']">
    <xsl:choose>
		<xsl:when test="TotalAmount = '0.00' and starts-with(Memo, 'VOID:')">
			<TxnVoidRq>
				<TxnVoidType>CreditMemo</TxnVoidType>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
					<CreditMemoRet>
				    	<xsl:copy-of select="TotalAmount"/>
				        <xsl:call-template name="CreditMemoInvoiceDetails"/>
				        <xsl:apply-templates select="CreditMemoLineRet | CreditMemoLineGroupRet"/>
				        <xsl:call-template name="DiscountSalesTaxLines"/>
					</CreditMemoRet>
			  	</AFXInfo>
			</TxnVoidRq>
		</xsl:when>
        <xsl:otherwise> 
		    <CreditMemoModRq>
		      <xsl:attribute name="requestID">
				  	<!-- Get the requestId from the parent CreditMemoQueryRs element -->
		        <xsl:value-of select="..//@requestID"/>
		      </xsl:attribute>
		      <CreditMemoMod>
		        <xsl:copy-of select="TxnID"/>
		  	    <AFXInfo>
		    	  <xsl:copy-of select="TotalAmount"/>
		  	    </AFXInfo>
		        <xsl:copy-of select="EditSequence"/>
		        <xsl:call-template name="CreditMemoInvoiceDetails"/>
		        <xsl:apply-templates select="CreditMemoLineRet | CreditMemoLineGroupRet">
					<xsl:with-param name="mod" select="1" />
				</xsl:apply-templates>
		      </CreditMemoMod>
		    </CreditMemoModRq>
        </xsl:otherwise> 
    </xsl:choose>  	
  </xsl:template>

  <xsl:template match="CreditMemoLineRet | CreditMemoLineGroupRet">

	<!-- Default the mod param to 0. The mod param is set to 1 only 
		 when invoked while transforming to Mod requests. -->
	<xsl:param name="mod" select="0"/>

 	<!-- Default the CreditMemoLineGroupMod param to 0. This param is set to 1 only 
 		 when invoked while transforming CreditMemoLineGroupRet query responses. -->
 	<xsl:param name="CreditMemoLineGroupMod" select="0"/>

    <xsl:if test="name(.) = 'CreditMemoLineRet'">
       <xsl:choose>
        <xsl:when test="$mod='0'">
	      <CreditMemoLineAdd>
	        <xsl:call-template name="ItemLineAddDetails"/>
	      </CreditMemoLineAdd>
        </xsl:when>
        <xsl:otherwise>
	      <CreditMemoLineMod>
	        <xsl:call-template name="ItemLineModDetails">
				<xsl:with-param name="ItemGroupLineMod" select="$CreditMemoLineGroupMod"/>
			</xsl:call-template>
      	  </CreditMemoLineMod>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>

	<!-- We no longer transform CreditMemoLineGroupRet aggregates to CreditMemoLineGroupAdd/Mod since 
		 the UI allows a lot of flexibility in how the individual line items can be added/
		 modified but the SDK CreditMemoLineGroupAdd aggregate does not list all of the line items 
		 in that group.
		 Instead we create an CreditMemoLineAdd/CreditMemoLineMod(with TxnLineId = -1 for items which have 
		 not been modified which essentially is an CreditMemoLineAdd) for each item in the group 
		 and discard the group.
	-->

    <xsl:if test="name(.) = 'CreditMemoLineGroupRet'">
       <xsl:choose>
        <xsl:when test="$mod='0'">
	 	  	<xsl:apply-templates select="CreditMemoLineRet | CreditMemoLineGroupRet"/>
        </xsl:when>
        <xsl:otherwise>
	      	<xsl:apply-templates select="CreditMemoLineRet | CreditMemoLineGroupRet">
				<xsl:with-param name="mod" select="1" />
				<xsl:with-param name="CreditMemoLineGroupMod" select="1" />
			</xsl:apply-templates>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>


  <xsl:template match="BillQueryRs/BillRet">
    <BillAddRq>
      <xsl:attribute name="requestID">
		  	<!-- Get the requestId from the parent BillRs element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <BillAdd>
	    <!-- TxnID is not part of the Bill Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
	    	<xsl:copy-of select="AmountDue"/>
	  	</AFXInfo>
        <xsl:copy-of select="VendorRef"/>
        <xsl:copy-of select="APAccountRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="DueDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="TermsRef"/>
        <xsl:copy-of select="Memo"/>
        <xsl:apply-templates select="LinkedTxn"/>
        <xsl:apply-templates select="ExpenseLineRet"/>
        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet"/>
      </BillAdd>
    </BillAddRq>
  </xsl:template>

  <!-- Mod responses have a proprietary mod attribute set to 1 in the *Ret element -->
  <xsl:template match="BillQueryRs/BillRet[@mod='1']">
    <xsl:choose>
		<xsl:when test="AmountDue = '0.00' and starts-with(Memo, 'VOID:')">
			<TxnVoidRq>
				<TxnVoidType>Bill</TxnVoidType>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
					<BillRet>
				    	<xsl:copy-of select="AmountDue"/>
				        <xsl:copy-of select="VendorRef"/>
				        <xsl:copy-of select="APAccountRef"/>
				        <xsl:copy-of select="TxnDate"/>
				        <xsl:copy-of select="DueDate"/>
				        <xsl:copy-of select="RefNumber"/>
				        <xsl:copy-of select="TermsRef"/>
				        <xsl:copy-of select="Memo"/>
				        <xsl:copy-of select="ClearExpenseLines"/>
				        <xsl:apply-templates select="ExpenseLineRet">
							<xsl:with-param name="mod" select="1" />
						</xsl:apply-templates>
				        <xsl:copy-of select="ClearItemLines"/>
				        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet">
							<xsl:with-param name="mod" select="1" />
						</xsl:apply-templates>
					</BillRet>
			  	</AFXInfo>
			</TxnVoidRq>
		</xsl:when>
        <xsl:otherwise> 
		    <BillModRq>
		      <xsl:attribute name="requestID">
				  	<!-- Get the requestId from the parent BillRs element -->
		        <xsl:value-of select="..//@requestID"/>
		      </xsl:attribute>
		      <BillMod>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
			    	<xsl:copy-of select="AmountDue"/>
			  	</AFXInfo>
		        <xsl:copy-of select="EditSequence"/>
		        <xsl:copy-of select="VendorRef"/>
		        <xsl:copy-of select="APAccountRef"/>
		        <xsl:copy-of select="TxnDate"/>
		        <xsl:copy-of select="DueDate"/>
		        <xsl:copy-of select="RefNumber"/>
		        <xsl:copy-of select="TermsRef"/>
		        <xsl:copy-of select="Memo"/>
		        <xsl:copy-of select="ClearExpenseLines"/>
		        <xsl:apply-templates select="ExpenseLineRet">
					<xsl:with-param name="mod" select="1" />
				</xsl:apply-templates>
		        <xsl:copy-of select="ClearItemLines"/>
		        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet">
					<xsl:with-param name="mod" select="1" />
				</xsl:apply-templates>
		      </BillMod>
		    </BillModRq>
        </xsl:otherwise> 
    </xsl:choose>  	
  </xsl:template>

  <xsl:template match="LinkedTxn">
    <LinkToTxnID>
      <xsl:value-of select="LinkedTxn/TxnID"/>
    </LinkToTxnID>
  </xsl:template>

  <xsl:template match="CheckQueryRs/CheckRet">
    <CheckAddRq>
      <xsl:attribute name="requestID">
		  	<!-- Get the requestId from the parent CheckRs element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <CheckAdd>
  	    <!-- TxnID and Amount are not part of the Check Add request but needed while
		 importing accountant changes on the client side. -->
	  	<AFXInfo>
        	<xsl:copy-of select="Amount"/>
	    	<xsl:copy-of select="TxnID"/>
	  	</AFXInfo>
        <xsl:copy-of select="AccountRef"/>
        <xsl:copy-of select="PayeeEntityRef"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="Memo"/>
        <xsl:copy-of select="Address"/>
        <xsl:copy-of select="IsToBePrinted"/>
        <xsl:apply-templates select="ExpenseLineRet"/>
        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet"/>
      </CheckAdd>
    </CheckAddRq>
  </xsl:template>

  <!-- Mod responses have a proprietary mod attribute set to 1 in the *Ret element -->
  <xsl:template match="CheckQueryRs/CheckRet[@mod='1']">

    <xsl:choose>
		<xsl:when test="Amount = '0.00' and starts-with(Memo, 'VOID:')">
			<TxnVoidRq>
				<TxnVoidType>Check</TxnVoidType>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
					<CheckRet>
			        	<xsl:copy-of select="Amount"/>
				        <xsl:copy-of select="AccountRef"/>
				        <xsl:copy-of select="PayeeEntityRef"/>
				        <xsl:copy-of select="RefNumber"/>
				        <xsl:copy-of select="TxnDate"/>
				        <xsl:copy-of select="Memo"/>
				        <xsl:copy-of select="Address"/>
				        <xsl:copy-of select="IsToBePrinted"/>
				        <xsl:copy-of select="ClearExpenseLines"/>
				        <xsl:apply-templates select="ExpenseLineRet">
							<xsl:with-param name="mod" select="1" />
						</xsl:apply-templates>
				        <xsl:copy-of select="ClearItemLines"/>
				        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet">
							<xsl:with-param name="mod" select="1" />
						</xsl:apply-templates>
					</CheckRet>
			  	</AFXInfo>
			</TxnVoidRq>
		</xsl:when>
        <xsl:otherwise> 
		    <CheckModRq>
		      <xsl:attribute name="requestID">
				  	<!-- Get the requestId from the parent CheckRs element -->
		        <xsl:value-of select="..//@requestID"/>
		      </xsl:attribute>
		      <CheckMod>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
		        	<xsl:copy-of select="Amount"/>
			  	</AFXInfo>
		        <xsl:copy-of select="EditSequence"/>
		        <xsl:copy-of select="AccountRef"/>
		        <xsl:copy-of select="PayeeEntityRef"/>
		        <xsl:copy-of select="RefNumber"/>
		        <xsl:copy-of select="TxnDate"/>
		        <xsl:copy-of select="Memo"/>
		        <xsl:copy-of select="Address"/>
		        <xsl:copy-of select="IsToBePrinted"/>
		        <xsl:copy-of select="ClearExpenseLines"/>
		        <xsl:apply-templates select="ExpenseLineRet">
					<xsl:with-param name="mod" select="1" />
				</xsl:apply-templates>
		        <xsl:copy-of select="ClearItemLines"/>
		        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet">
					<xsl:with-param name="mod" select="1" />
				</xsl:apply-templates>
		      </CheckMod>
		    </CheckModRq>
        </xsl:otherwise> 
    </xsl:choose>  	
  </xsl:template>

  <xsl:template match="CreditCardChargeQueryRs/CreditCardChargeRet">
    <CreditCardChargeAddRq>
      <xsl:attribute name="requestID">
		  	<!-- Get the requestId from the parent CreditCardChargeRs element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <CreditCardChargeAdd>
	    <!-- TxnID is not part of the CreditCardCharge Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
	    	<xsl:copy-of select="Amount"/>
	  	</AFXInfo>
        <xsl:copy-of select="AccountRef"/>
        <xsl:copy-of select="PayeeEntityRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="Memo"/>
        <xsl:apply-templates select="ExpenseLineRet"/>
        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet"/>
      </CreditCardChargeAdd>
    </CreditCardChargeAddRq>
  </xsl:template>

  <!-- Mod responses have a proprietary mod attribute set to 1 in the *Ret element -->
  <xsl:template match="CreditCardChargeQueryRs/CreditCardChargeRet[@mod='1']">

    <xsl:choose>
		<xsl:when test="Amount = '0.00' and starts-with(Memo, 'VOID:')">
			<TxnVoidRq>
				<TxnVoidType>CreditCardCharge</TxnVoidType>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
					<CreditCardChargeRet>
					   	<xsl:copy-of select="Amount"/>
				        <xsl:copy-of select="AccountRef"/>
				        <xsl:copy-of select="PayeeEntityRef"/>
				        <xsl:copy-of select="TxnDate"/>
				        <xsl:copy-of select="RefNumber"/>
				        <xsl:copy-of select="Memo"/>
				        <xsl:copy-of select="ClearExpenseLines"/>
				        <xsl:apply-templates select="ExpenseLineRet">
							<xsl:with-param name="mod" select="1" />
						</xsl:apply-templates>
				        <xsl:copy-of select="ClearItemLines"/>
				        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet">
							<xsl:with-param name="mod" select="1" />
						</xsl:apply-templates>
					</CreditCardChargeRet>
			  	</AFXInfo>
			</TxnVoidRq>
		</xsl:when>
        <xsl:otherwise>
		    <CreditCardChargeModRq>
		      <xsl:attribute name="requestID">
				  	<!-- Get the requestId from the parent CreditCardChargeRs element -->
		        <xsl:value-of select="..//@requestID"/>
		      </xsl:attribute>
		      <CreditCardChargeMod>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
		        	<xsl:copy-of select="Amount"/>
			  	</AFXInfo>
		        <xsl:copy-of select="EditSequence"/>
		        <xsl:copy-of select="AccountRef"/>
		        <xsl:copy-of select="PayeeEntityRef"/>
		        <xsl:copy-of select="TxnDate"/>
		        <xsl:copy-of select="RefNumber"/>
		        <xsl:copy-of select="Memo"/>
		        <xsl:copy-of select="ClearExpenseLines"/>
		        <xsl:apply-templates select="ExpenseLineRet">
					<xsl:with-param name="mod" select="1" />
				</xsl:apply-templates>
		        <xsl:copy-of select="ClearItemLines"/>
		        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet">
					<xsl:with-param name="mod" select="1" />
				</xsl:apply-templates>
		      </CreditCardChargeMod>
		    </CreditCardChargeModRq>
        </xsl:otherwise> 
    </xsl:choose>  	

  </xsl:template>

  <xsl:template match="CreditCardCreditQueryRs/CreditCardCreditRet">
    <CreditCardCreditAddRq>
      <xsl:attribute name="requestID">
		  	<!-- Get the requestId from the parent CreditCardChargeRs element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <CreditCardCreditAdd>
	    <!-- TxnID is not part of the CreditCardCredit Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
	    	<xsl:copy-of select="Amount"/>
	  	</AFXInfo>
        <xsl:copy-of select="AccountRef"/>
        <xsl:copy-of select="PayeeEntityRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="Memo"/>
        <xsl:apply-templates select="ExpenseLineRet"/>
        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet"/>
      </CreditCardCreditAdd>
    </CreditCardCreditAddRq>
  </xsl:template>

  <!-- Mod responses have a proprietary mod attribute set to 1 in the *Ret element -->
  <xsl:template match="CreditCardCreditQueryRs/CreditCardCreditRet[@mod='1']">
    <xsl:choose>
		<xsl:when test="Amount = '0.00' and starts-with(Memo, 'VOID:')">
			<TxnVoidRq>
				<TxnVoidType>CreditCardCredit</TxnVoidType>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
					<CreditCardCreditRet>
				    	<xsl:copy-of select="Amount"/>
				        <xsl:copy-of select="AccountRef"/>
				        <xsl:copy-of select="PayeeEntityRef"/>
				        <xsl:copy-of select="TxnDate"/>
				        <xsl:copy-of select="RefNumber"/>
				        <xsl:copy-of select="Memo"/>
				        <xsl:apply-templates select="ExpenseLineRet"/>
				        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet"/>
					</CreditCardCreditRet>
			  	</AFXInfo>
			</TxnVoidRq>
		</xsl:when>
        <xsl:otherwise> 
		    <CreditCardCreditModRq>
		      <xsl:attribute name="requestID">
				  	<!-- Get the requestId from the parent CreditCardChargeRs element -->
		        <xsl:value-of select="..//@requestID"/>
		      </xsl:attribute>
		      <CreditCardCreditMod>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
			    	<xsl:copy-of select="Amount"/>
			  	</AFXInfo>
		        <xsl:copy-of select="EditSequence"/>
		        <xsl:copy-of select="AccountRef"/>
		        <xsl:copy-of select="PayeeEntityRef"/>
		        <xsl:copy-of select="TxnDate"/>
		        <xsl:copy-of select="RefNumber"/>
		        <xsl:copy-of select="Memo"/>
		        <xsl:copy-of select="ClearExpenseLines"/>
		        <xsl:apply-templates select="ExpenseLineRet">
					<xsl:with-param name="mod" select="1" />
				</xsl:apply-templates>
		        <xsl:copy-of select="ClearItemLines"/>
		        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet">
					<xsl:with-param name="mod" select="1" />
				</xsl:apply-templates>
		      </CreditCardCreditMod>
		    </CreditCardCreditModRq>
        </xsl:otherwise> 
    </xsl:choose>  	

  </xsl:template>

  <xsl:template match="SalesReceiptQueryRs/SalesReceiptRet">
    <SalesReceiptAddRq>
      <xsl:attribute name="requestID">
		  	<!-- Get the requestId from the parent SalesReceiptRs element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <SalesReceiptAdd>
	    <!-- TxnID is not part of the SalesReceipt Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
	    	<xsl:copy-of select="TotalAmount"/>
	  	</AFXInfo>
        <xsl:call-template name="SalesReceiptDetails"/>
        <xsl:apply-templates select="SalesReceiptLineRet | SalesReceiptLineGroupRet"/>
        <xsl:call-template name="DiscountSalesTaxLines"/>
      </SalesReceiptAdd>
    </SalesReceiptAddRq>
  </xsl:template>


  <!-- Mod responses have a proprietary mod attribute set to 1 in the *Ret element -->
  <xsl:template match="SalesReceiptQueryRs/SalesReceiptRet[@mod='1']">
    <xsl:choose>
		<xsl:when test="TotalAmount = '0.00' and starts-with(Memo, 'VOID:')">
			<TxnVoidRq>
				<TxnVoidType>SalesReceipt</TxnVoidType>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
					<SalesReceiptRet>
				    	<xsl:copy-of select="TotalAmount"/>
				        <xsl:call-template name="SalesReceiptDetails"/>
				        <xsl:apply-templates select="SalesReceiptLineRet | SalesReceiptLineGroupRet"/>
				        <xsl:call-template name="DiscountSalesTaxLines"/>
					</SalesReceiptRet>
			  	</AFXInfo>
			</TxnVoidRq>
		</xsl:when>
        <xsl:otherwise> 
		    <SalesReceiptModRq>
		      <xsl:attribute name="requestID">
				  	<!-- Get the requestId from the parent SalesReceiptRs element -->
		        <xsl:value-of select="..//@requestID"/>
		      </xsl:attribute>
		      <SalesReceiptMod>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
			    	<xsl:copy-of select="TotalAmount"/>
			  	</AFXInfo>
		        <xsl:copy-of select="EditSequence"/>
		        <xsl:call-template name="SalesReceiptDetails"/>
		        <xsl:apply-templates select="SalesReceiptLineRet | SalesReceiptLineGroupRet">
					<xsl:with-param name="mod" select="1" />
				</xsl:apply-templates>
		      </SalesReceiptMod>
		    </SalesReceiptModRq>
        </xsl:otherwise> 
    </xsl:choose>  	
  </xsl:template>


  <xsl:template match="SalesReceiptLineRet | SalesReceiptLineGroupRet">

	<!-- Default the mod param to 0. The mod param is set to 1 only 
		 when invoked while transforming to Mod requests. -->
  	<xsl:param name="mod" select="0"/>

 	<!-- Default the SalesReceiptLineGroupMod param to 0. This param is set to 1 only 
 		 when invoked while transforming SalesReceiptLineGroupRet query responses. -->
 	<xsl:param name="SalesReceiptLineGroupMod" select="0"/>

    <xsl:if test="name(.) = 'SalesReceiptLineRet'">
       <xsl:choose>
        <xsl:when test="$mod='0'">
	      <SalesReceiptLineAdd>
	        <xsl:call-template name="ItemLineAddDetails"/>
	      </SalesReceiptLineAdd>
        </xsl:when>
        <xsl:otherwise>
	      <SalesReceiptLineMod>
	        <xsl:call-template name="ItemLineModDetails">
				<xsl:with-param name="ItemGroupLineMod" select="$SalesReceiptLineGroupMod"/>
			</xsl:call-template>
      	  </SalesReceiptLineMod>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>

	<!-- We no longer transform SalesReceiptLineGroupRet aggregates to SalesReceiptLineGroupAdd/Mod since 
		 the UI allows a lot of flexibility in how the individual line items can be added/
		 modified but the SDK SalesReceiptLineGroupAdd aggregate does not list all of the line items 
		 in that group.
		 Instead we create an SalesReceiptLineAdd/SalesReceiptLineMod(with TxnLineId = -1 for items which have 
		 not been modified which essentially is an SalesReceiptLineAdd) for each item in the group 
		 and discard the group.
	-->

    <xsl:if test="name(.) = 'SalesReceiptLineGroupRet'">
       <xsl:choose>
        <xsl:when test="$mod='0'">
		    <xsl:apply-templates select="SalesReceiptLineRet | SalesReceiptLineGroupRet"/>
        </xsl:when>
        <xsl:otherwise>
	        <xsl:apply-templates select="SalesReceiptLineRet | SalesReceiptLineGroupRet">
				<xsl:with-param name="mod" select="1" />
				<xsl:with-param name="SalesReceiptLineGroupMod" select="1" />
			</xsl:apply-templates>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>


  <xsl:template match="DepositQueryRs/DepositRet">
    <DepositAddRq>
      <xsl:attribute name="requestID">
		  	<!-- Get the requestId from the parent DepositRs element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <DepositAdd>
	    <!-- TxnID is not part of the Deposit Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
	    	<xsl:copy-of select="DepositTotal"/>
	  	</AFXInfo>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="DepositToAccountRef"/>
        <xsl:copy-of select="Memo"/>
        <xsl:if test="CashBackInfoRet">
          <CashBackInfoAdd>
            <xsl:copy-of select="CashBackInfoRet/AccountRef"/>
            <xsl:copy-of select="CashBackInfoRet/Memo"/>
            <xsl:copy-of select="CashBackInfoRet/Amount"/>
          </CashBackInfoAdd>
        </xsl:if>
        <xsl:apply-templates select="DepositLineRet"/>
      </DepositAdd>
    </DepositAddRq>
  </xsl:template>

  <xsl:template match="DepositLineRet">

    <xsl:choose>
		<!-- In cases where we come across deposit transaction queries which do not have
			 AccountRef under DepositLineRet we do not generate a corresponding DepositLineAdd
			 since AccountRef is a required field under DepositLineAdd in a DepositAddRq -->
    	<xsl:when test="TxnType = 'Deposit' and not(AccountRef)">
		</xsl:when> 
	    <xsl:otherwise>
		    <DepositLineAdd>
		      <xsl:choose>
		        <xsl:when test="TxnType = 'ReceivePayment' or TxnType = 'SalesReceipt'">
		          <PaymentTxnID>
		            <xsl:value-of select="TxnID"/>
		          </PaymentTxnID>  
		          <AFXInfo>
		            <xsl:copy-of select="TxnType"/>
		            <xsl:copy-of select="EntityRef"/>
		            <xsl:copy-of select="AccountRef"/>
		            <xsl:copy-of select="Memo"/>
		            <xsl:copy-of select="CheckNumber"/>
		            <xsl:copy-of select="PaymentMethodRef"/>
		            <xsl:copy-of select="ClassRef"/>
		            <xsl:copy-of select="Amount"/>
		          </AFXInfo>          
		        </xsl:when>
		        <xsl:otherwise>
		  	  	  <AFXInfo>
				   	<xsl:copy-of select="TxnID"/>
				   	<xsl:copy-of select="TxnLineID"/>
				  </AFXInfo>
		          <xsl:copy-of select="EntityRef"/>
		          <xsl:copy-of select="AccountRef"/>
		          <xsl:copy-of select="Memo"/>
		          <xsl:copy-of select="CheckNumber"/>
		          <xsl:copy-of select="PaymentMethodRef"/>
		          <xsl:copy-of select="ClassRef"/>
		          <xsl:copy-of select="Amount"/>
		        </xsl:otherwise>
		      </xsl:choose>
		    </DepositLineAdd>
       </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="InventoryAdjustmentQueryRs/InventoryAdjustmentRet">
	    <InventoryAdjustmentAddRq>
	      <xsl:attribute name="requestID">
			  	<!-- Get the requestId from the parent SalesReceiptRs element -->
	        <xsl:value-of select="..//@requestID"/>
	      </xsl:attribute>
	      <InventoryAdjustmentAdd>
		    <!-- TxnID is not part of the InventoryAdjustment Add request but needed while
				 importing accountant changes on the client side. -->
		  	<AFXInfo>
		    	<xsl:copy-of select="TxnID"/>
		  	</AFXInfo>
	        <xsl:copy-of select="AccountRef"/>
	        <xsl:copy-of select="TxnDate"/>
	        <xsl:copy-of select="RefNumber"/>
	        <xsl:copy-of select="CustomerRef"/>
	        <xsl:copy-of select="ClassRef"/>
	        <xsl:copy-of select="Memo"/>
	        <xsl:apply-templates select="InventoryAdjustmentLineRet"/>
	      </InventoryAdjustmentAdd>
	    </InventoryAdjustmentAddRq>
  </xsl:template>

  <xsl:template match="InventoryAdjustmentLineRet">
    <InventoryAdjustmentLineAdd>
	  <AFXInfo>
	  	<xsl:copy-of select="TxnLineID"/>
	  </AFXInfo>
      <xsl:copy-of select="ItemRef"/>
      <xsl:if test="QuantityDifference">
        <QuantityAdjustment>
          <xsl:copy-of select="QuantityDifference"/>
        </QuantityAdjustment>
      </xsl:if>
    </InventoryAdjustmentLineAdd>
  </xsl:template>


 
  <xsl:template match="JournalEntryQueryRs/JournalEntryRet"> 
     <JournalEntryAddRq>
      <xsl:attribute name="requestID">
		  	<!-- Get the requestId from the parent JournalEntryRs element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <JournalEntryAdd>
	    <!-- TxnID is not part of the JournalEntry Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
	  	</AFXInfo>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="Memo"/>
        <!--<xsl:copy-of select="IsAdjustment"/>-->
        <xsl:apply-templates select="JournalDebitLine | JournalCreditLine"/>
      </JournalEntryAdd>
    </JournalEntryAddRq>
  </xsl:template>

  <!-- Mod responses have a proprietary mod attribute set to 1 in the *Ret element -->
  <xsl:template match="JournalEntryQueryRs/JournalEntryRet[@mod='1']">

    <xsl:choose>
		<xsl:when test="(JournalDebitLine/Amount = '0.00' and starts-with(JournalDebitLine/Memo, 'VOID:')) or (JournalCreditLine/Amount = '0.00' and starts-with(JournalCreditLine/Memo, 'VOID:'))">
			<TxnVoidRq>
				<TxnVoidType>JournalEntry</TxnVoidType>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
					<JournalEntryRet>
				        <xsl:copy-of select="TxnDate"/>
				        <xsl:copy-of select="RefNumber"/>
				        <xsl:copy-of select="Memo"/>
				        <xsl:apply-templates select="JournalDebitLine | JournalCreditLine"/>
					</JournalEntryRet>
			  	</AFXInfo>
			</TxnVoidRq>
		</xsl:when>
        <xsl:otherwise> 
		    <JournalEntryModRq>
		      <xsl:attribute name="requestID">
				  	<!-- Get the requestId from the parent JournalEntryRs element -->
		        <xsl:value-of select="..//@requestID"/>
		      </xsl:attribute>
		      <JournalEntryMod>
		        <xsl:copy-of select="TxnID"/>
		        <xsl:copy-of select="EditSequence"/>
		        <xsl:copy-of select="TxnDate"/>
		        <xsl:copy-of select="RefNumber"/>
		        <!--<xsl:copy-of select="IsAdjustment"/>-->
		        <xsl:apply-templates select="JournalDebitLine | JournalCreditLine">
					<xsl:with-param name="mod" select="1" />
				</xsl:apply-templates>
		      </JournalEntryMod>
		    </JournalEntryModRq>
        </xsl:otherwise> 
    </xsl:choose>  	

  </xsl:template>

  <!-- Template which processes the JournalDebitLine or JournalCreditLine element -->
  <xsl:template match="JournalDebitLine | JournalCreditLine">

	<!-- Default the mod param to 0. The mod param is set to 1 only 
		 when invoked while transforming to Mod requests. -->
  	<xsl:param name="mod" select="0"/>

    <xsl:if test="name(.) = 'JournalCreditLine' ">
       <xsl:choose>
        <xsl:when test="$mod='0'">
	      <JournalCreditLine>
		  	<AFXInfo>	
	        	<xsl:copy-of select="TxnLineID"/>
			</AFXInfo>
	        <xsl:call-template name="JournalLineDetails"/>
	      </JournalCreditLine>
        </xsl:when>
        <xsl:otherwise>
	      <JournalLineMod>
	        <xsl:call-template name="TxnLineIdForMods"/>
			<JournalLineType>Credit</JournalLineType>
	        <xsl:call-template name="JournalLineDetails"/>
	      </JournalLineMod>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>

    <xsl:if test="name(.) = 'JournalDebitLine' ">
       <xsl:choose>
        <xsl:when test="$mod='0'">
	      <JournalDebitLine>
		  	<AFXInfo>	
	        	<xsl:copy-of select="TxnLineID"/>
			</AFXInfo>
	        <xsl:call-template name="JournalLineDetails"/>
	      </JournalDebitLine>
        </xsl:when>
        <xsl:otherwise>
	      <JournalLineMod>
	        <xsl:call-template name="TxnLineIdForMods"/>
			<JournalLineType>Debit</JournalLineType>
	        <xsl:call-template name="JournalLineDetails"/>
	      </JournalLineMod>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>

  <!-- Common template to process the Credit/Debit details. -->
  <xsl:template name="JournalLineDetails">
    <xsl:copy-of select="AccountRef"/>
    <xsl:copy-of select="Amount"/>
    <xsl:copy-of select="Memo"/>
    <xsl:copy-of select="EntityRef"/>
    <xsl:copy-of select="ClassRef"/>
    <xsl:copy-of select="BillableStatus"/>
  </xsl:template>

  <xsl:template name="CreditMemoInvoiceDetails">
    <xsl:copy-of select="CustomerRef"/>
    <xsl:copy-of select="ClassRef"/>
    <xsl:copy-of select="ARAccountRef"/>
    <xsl:copy-of select="TemplateRef"/>
    <xsl:copy-of select="TxnDate"/>
    <xsl:copy-of select="RefNumber"/>
    <xsl:copy-of select="BillAddress"/>
    <xsl:copy-of select="ShipAddress"/>
    <xsl:copy-of select="IsPending"/>
    <xsl:copy-of select="PONumber"/>
    <xsl:copy-of select="TermsRef"/>
    <xsl:copy-of select="DueDate"/>
    <xsl:copy-of select="SalesRepRef"/>
    <xsl:copy-of select="FOB"/>
    <xsl:copy-of select="ShipDate"/>
    <xsl:copy-of select="ShipMethodRef"/>
    <xsl:copy-of select="ItemSalesTaxRef"/>
    <xsl:copy-of select="Memo"/>
    <xsl:copy-of select="CustomerMsgRef"/>
    <xsl:copy-of select="IsToBePrinted"/>
    <xsl:copy-of select="CustomerSalesTaxCodeRef"/>
  </xsl:template>

  <xsl:template name="DiscountSalesTaxLines">
    <xsl:if test="DiscountLineRet">
      <DepositLineAdd>
        <xsl:copy-of select="Amount"/>
        <xsl:copy-of select="RatePercent"/>
        <xsl:copy-of select="IsTaxable"/>
        <xsl:copy-of select="AccountRef"/>
      </DepositLineAdd>
    </xsl:if>
    <xsl:if test="SalesTaxLineRet">
      <SalesTaxLineAdd>
        <xsl:copy-of select="Amount"/>
        <xsl:copy-of select="RatePercent"/>
        <xsl:copy-of select="AccountRef"/>
        <xsl:if test="ShippingLineRet">
          <ShippingLineAdd>
            <xsl:copy-of select="Amount"/>
            <xsl:copy-of select="AccountRef"/>
          </ShippingLineAdd>
        </xsl:if>
      </SalesTaxLineAdd>
    </xsl:if>
  </xsl:template>

  <xsl:template name="ItemLineAddDetails">
  	<AFXInfo>	
    	<xsl:copy-of select="TxnLineID"/>
	</AFXInfo>
    <xsl:copy-of select="ItemRef"/>
    <xsl:copy-of select="Desc"/>

	<!-- If Quantity is absent and rate/ratepercent AND the amount are present then we skip the rate/ratepercent 
		 since including the rate in that condition causes a SDK error. 
		 (The SDK 6.0 reference guide says that in the above condition 
		 "the Rate you provide will be ignored, and you will receive a warning" but in reality the SDK throws an error.)-->
    <xsl:choose>
		<xsl:when test="Quantity">
        	<xsl:copy-of select="Quantity"/>
		    <xsl:copy-of select="Rate"/>
    		<xsl:copy-of select="RatePercent"/>
    	</xsl:when>
	    <xsl:otherwise>
			<xsl:if test="Rate or RatePercent">
			    <xsl:choose>				
					<xsl:when test="Amount">
			    	</xsl:when>
				    <xsl:otherwise>
					    <xsl:copy-of select="Rate"/>
    					<xsl:copy-of select="RatePercent"/>			
				    </xsl:otherwise>
			  	</xsl:choose>
			</xsl:if>
	    </xsl:otherwise>
  	</xsl:choose>

 	<xsl:copy-of select="ClassRef"/>
    <xsl:copy-of select="Amount"/>    
    <xsl:copy-of select="ServiceDate"/>
    <xsl:copy-of select="SalesTaxCodeRef"/>
    <xsl:copy-of select="IsTaxable"/>
    <xsl:apply-templates select="DataExtRet"/>
  </xsl:template>

  <xsl:template name="ItemLineModDetails">

  	<xsl:param name="ItemGroupLineMod" select="0"/>

    <xsl:call-template name="TxnLineIdForMods">
		<xsl:with-param name="ItemGroupLineMod" select="$ItemGroupLineMod"/>
	</xsl:call-template>

    <xsl:copy-of select="ItemRef"/>
    <Desc><xsl:value-of select="Desc"/></Desc>

	<!-- If Quantity is absent and rate/ratepercent AND the amount are present then we skip the rate/ratepercent 
		 since including the rate in that condition causes a SDK error. 
		 (The SDK 6.0 reference guide says that in the above condition 
		 "the Rate you provide will be ignored, and you will receive a warning" but in reality the SDK throws an error.)-->
    <xsl:choose>
		<xsl:when test="Quantity">
        	<xsl:copy-of select="Quantity"/>
		    <xsl:copy-of select="Rate"/>
    		<xsl:copy-of select="RatePercent"/>
    	</xsl:when>
	    <xsl:otherwise>
			<xsl:if test="Rate or RatePercent">
			    <xsl:choose>				
					<xsl:when test="Amount">
			    	</xsl:when>
				    <xsl:otherwise>
					    <xsl:copy-of select="Rate"/>
    					<xsl:copy-of select="RatePercent"/>
				    </xsl:otherwise>
			  	</xsl:choose>
			</xsl:if>
	    </xsl:otherwise>
  	</xsl:choose>

    <xsl:choose>				
		<xsl:when test="ClassRef">
    		<xsl:copy-of select="ClassRef"/>
    	</xsl:when>
	    <xsl:otherwise>
			<ClassRef/>
	    </xsl:otherwise>
  	</xsl:choose>

    <xsl:copy-of select="Amount"/>
    <xsl:copy-of select="ServiceDate"/>
    <xsl:copy-of select="SalesTaxCodeRef"/>
  </xsl:template>

  <xsl:template name="ItemLineGroupAddDetails">
  	<AFXInfo>	
    	<xsl:copy-of select="TxnLineID"/>
	</AFXInfo>
    <xsl:copy-of select="ItemGroupRef"/>
    <xsl:copy-of select="Quantity"/>
    <xsl:apply-templates select="DataExtRet"/>
  </xsl:template>

  <xsl:template name="SalesReceiptDetails">
        <xsl:copy-of select="CustomerRef"/>
        <xsl:copy-of select="ClassRef"/>
        <xsl:copy-of select="TemplateRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="BillAddress"/>
        <xsl:copy-of select="ShipAddress"/>
        <xsl:copy-of select="IsPending"/>
        <xsl:copy-of select="CheckNumber"/>
        <xsl:copy-of select="PaymentMethodRef"/>
        <xsl:copy-of select="DueDate"/>
        <xsl:copy-of select="SalesRepRef"/>
        <xsl:copy-of select="ShipDate"/>
        <xsl:copy-of select="ShipMethodRef"/>
        <xsl:copy-of select="FOB"/>
        <xsl:copy-of select="ItemSalesTaxRef"/>
        <xsl:copy-of select="Memo"/>
        <xsl:copy-of select="CustomerMsgRef"/>
        <xsl:copy-of select="IsToBePrinted"/>
        <xsl:copy-of select="CustomerSalesTaxCodeRef"/>
        <xsl:copy-of select="DepositToAccountRef"/>
  </xsl:template>


  <xsl:template match="DataExtRet">
    <DataExt>
      <xsl:copy-of select="OwnerId"/>
      <xsl:copy-of select="DataExtName"/>
      <xsl:copy-of select="DataExtValue"/>
    </DataExt>
  </xsl:template>

  <xsl:template match="AppliedToTxnRet">

	<!-- Default the mod param to 0. The mod param is set to 1 only 
		 when invoked while transforming to Mod requests. -->
	   <xsl:param name="mod" select="0"/>

       <xsl:choose>
        <xsl:when test="$mod='0'">
		    <AppliedToTxnAdd>
	        	<xsl:call-template name="AppliedToTxnRetDetails"/>
		    </AppliedToTxnAdd>
        </xsl:when>
        <xsl:otherwise>
	      <AppliedToTxnMod>
    	    <xsl:call-template name="AppliedToTxnRetDetails"/>
      	  </AppliedToTxnMod>
        </xsl:otherwise>
      </xsl:choose>
  </xsl:template>

  <xsl:template name="AppliedToTxnRetDetails">
      <xsl:copy-of select="TxnID"/>
      <xsl:if test="Amount">
        <PaymentAmount>
          <xsl:value-of select="Amount"/>
        </PaymentAmount>
      </xsl:if>
      <xsl:copy-of select="DiscountAmount"/>
      <xsl:copy-of select="DiscountAccountRef"/>
      <AFXInfo>
        <xsl:copy-of select="TxnType"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select ="BalanceRemaining"/>
      </AFXInfo>
  </xsl:template>

  <xsl:template match="ExpenseLineRet">
	
	<!-- Default the mod param to 0. The mod param is set to 1 only 
		 when invoked while transforming to Mod requests. -->
	<xsl:param name="mod" select="0"/>

       <xsl:choose>
        <xsl:when test="$mod='0'">
	      <ExpenseLineAdd>
		  	<AFXInfo>	
	        	<xsl:copy-of select="TxnLineID"/>
			</AFXInfo>
	        <xsl:call-template name="ExpenseLineRetDetails"/>
	      </ExpenseLineAdd>
        </xsl:when>
        <xsl:otherwise>
	      <ExpenseLineMod>
	        <xsl:call-template name="TxnLineIdForMods"/>
    	    <xsl:call-template name="ExpenseLineRetDetails"/>
      	  </ExpenseLineMod>
        </xsl:otherwise>
      </xsl:choose>
  </xsl:template>

  <xsl:template name="ExpenseLineRetDetails">
        <xsl:copy-of select="AccountRef"/>
        <xsl:copy-of select="Amount"/>
        <xsl:copy-of select="Memo"/>
        <xsl:copy-of select="CustomerRef"/>
        <xsl:copy-of select="ClassRef"/>
        <xsl:copy-of select="BillableStatus"/>
  </xsl:template>




  <xsl:template match="ItemLineRet | ItemGroupLineRet">

	<!-- Default the mod param to 0. The mod param is set to 1 only 
		 when invoked while transforming to Mod requests. -->
	<xsl:param name="mod" select="0"/>

	<!-- Default the ItemGroupLineMod param to 0. This param is set to 1 only 
		 when invoked while transforming ItemGroupLineRet query responses. -->
	<xsl:param name="ItemGroupLineMod" select="0"/>

    <xsl:if test="name(.) = 'ItemLineRet' ">
       <xsl:choose>
        <xsl:when test="$mod='0'">
	      <ItemLineAdd>
		  	<AFXInfo>	
	        	<xsl:copy-of select="TxnLineID"/>
			</AFXInfo>
	        <xsl:call-template name="ItemLineRetDetails"/>
	      </ItemLineAdd>
        </xsl:when>
        <xsl:otherwise>
	       <xsl:choose>
		   	  <!-- While modifying a line item if an ItemRef is not specified 
			  	   then the quantity field does not get updated to 0 and so the inventory does not 
				   get re-adjusted appropriately.
				   The solution is to leave out generating the ItemLineMod in case the ItemRef is 
				   absent and amount = 0 so that the inventory gets adjusted accordingly.
			  -->
			  <xsl:when test="not(ItemRef) and Amount='0.00'">
	          </xsl:when>
		      <xsl:otherwise>		
			      <ItemLineMod>
			        <xsl:call-template name="TxnLineIdForMods">
						<xsl:with-param name="ItemGroupLineMod" select="$ItemGroupLineMod"/>
					</xsl:call-template>
		    	    <xsl:call-template name="ItemLineRetDetails"/>
		      	  </ItemLineMod>
	        </xsl:otherwise>
	      </xsl:choose>
	    </xsl:otherwise>
      </xsl:choose>
    </xsl:if>

	<!-- We no longer transform ItemGroupLineRet aggregates to ItemGroupLineAdd/Mod since 
		 the UI allows a lot of flexibility in how the individual line items can be added/
		 modified but the SDK ItemGroupLineAdd aggregate does not list all of the line items 
		 in that group.
		 Instead we create an ItemLineAdd/ItemLineMod(with TxnLineId = -1 for items which have 
		 not been modified which essentially is an ItemLineAdd) for each item in the group 
		 and discard the group.
	-->
    <xsl:if test="name(.) = 'ItemGroupLineRet' ">
       <xsl:choose>
        <xsl:when test="$mod='0'">
	        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet"/>
        </xsl:when>
        <xsl:otherwise>
	        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet">
				<xsl:with-param name="mod" select="1" />
				<xsl:with-param name="ItemGroupLineMod" select="1" />
			</xsl:apply-templates>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:if>
  </xsl:template>


  <xsl:template name="ItemLineRetDetails">
        <xsl:copy-of select="ItemRef"/>
        <xsl:copy-of select="Desc"/>
        <xsl:copy-of select="Quantity"/>
        <xsl:copy-of select="Cost"/>
        <xsl:copy-of select="Amount"/>
        <xsl:copy-of select="CustomerRef"/>
        <xsl:copy-of select="ClassRef"/>
        <xsl:copy-of select="BillableStatus"/>
  </xsl:template>


  <xsl:template match ="ReceivePaymentQueryRs/ReceivePaymentRet">
    <ReceivePaymentAddRq>
      <xsl:attribute name="requestID">
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ReceivePaymentAdd>
	    <!-- TxnID is not part of the ReceivePayment Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
	    	<xsl:copy-of select="TotalAmount"/>
	  	</AFXInfo>
        <xsl:copy-of select="CustomerRef"/>
        <xsl:copy-of select="ARAccountRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="TotalAmount"/>
        <xsl:copy-of select="PaymentMethodRef"/>
        <xsl:copy-of select="Memo"/>
        <xsl:copy-of select="DepositToAccountRef"/>
        <xsl:choose>
	   		<xsl:when test="AppliedToTxnRet">
	        	<xsl:apply-templates select="AppliedToTxnRet"/>
	        </xsl:when>
	        <xsl:otherwise>
				<IsAutoApply>false</IsAutoApply>
	        </xsl:otherwise>
        </xsl:choose>
      </ReceivePaymentAdd>
    </ReceivePaymentAddRq>
  </xsl:template>

  <!-- Mod responses have a proprietary mod attribute set to 1 in the *Ret element -->
  <xsl:template match ="ReceivePaymentQueryRs/ReceivePaymentRet[@mod='1']">
    <ReceivePaymentModRq>
      <xsl:attribute name="requestID">
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ReceivePaymentMod>
        <xsl:copy-of select="TxnID"/>
	  	<AFXInfo>
	    	<xsl:copy-of select="TotalAmount"/>
	  	</AFXInfo>
        <xsl:copy-of select="EditSequence"/>
        <xsl:copy-of select="CustomerRef"/>
        <xsl:copy-of select="ARAccountRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="TotalAmount"/>
        <xsl:copy-of select="PaymentMethodRef"/>
        <xsl:copy-of select="Memo"/>
        <xsl:copy-of select="DepositToAccountRef"/>
        <xsl:apply-templates select="AppliedToTxnRet">
			<xsl:with-param name="mod" select="1" />
		</xsl:apply-templates>
      </ReceivePaymentMod>
    </ReceivePaymentModRq>
  </xsl:template>

  <xsl:template match="VendorCreditQueryRs/VendorCreditRet">
    <VendorCreditAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <VendorCreditAdd>
	    <!-- TxnID is not part of the VendorCredit Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
        <xsl:copy-of select="CreditAmount"/>
	  	</AFXInfo>
        <xsl:copy-of select="VendorRef"/>
        <xsl:copy-of select="APAccountRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="Memo"/>
        <xsl:apply-templates select="ExpenseLineRet"/>
		<xsl:apply-templates select="ItemLineRet | ItemGroupLineRet"/>
      </VendorCreditAdd>
    </VendorCreditAddRq>
  </xsl:template>

  <xsl:template match="BillPaymentCheckQueryRs/BillPaymentCheckRet">
    <BillPaymentCheckAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <BillPaymentCheckAdd>
	    <!-- TxnID is not part of the BillPaymentCheck Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
	    	<xsl:copy-of select="Amount"/>
	  	</AFXInfo>
        <xsl:copy-of select="PayeeEntityRef"/>
        <xsl:copy-of select="APAccountRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="BankAccountRef"/>
        <xsl:choose>
	   		<xsl:when test="RefNumber">
		        <xsl:copy-of select="RefNumber"/>
	        </xsl:when>
	        <xsl:otherwise>
		        <xsl:copy-of select="IsToBePrinted"/>
	        </xsl:otherwise>
        </xsl:choose>
        <xsl:copy-of select="Memo"/>
        <xsl:apply-templates select="AppliedToTxnRet"/>
      </BillPaymentCheckAdd>
    </BillPaymentCheckAddRq>
  </xsl:template>

  <!-- Mod responses have a proprietary mod attribute set to 1 in the *Ret element -->
  <xsl:template match="BillPaymentCheckQueryRs/BillPaymentCheckRet[@mod='1']">

    <xsl:choose>
		<xsl:when test="Amount = '0.00'">
			<TxnVoidRq>
				<TxnVoidType>BillPaymentCheck</TxnVoidType>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
					<BillPaymentCheckRet>
				    	<xsl:copy-of select="Amount"/>
				    	<xsl:copy-of select="PayeeEntityRef"/>
				        <xsl:copy-of select="TxnDate"/>
				        <xsl:copy-of select="BankAccountRef"/>
				        <xsl:choose>
					   		<xsl:when test="RefNumber">
						        <xsl:copy-of select="RefNumber"/>
					        </xsl:when>
					        <xsl:otherwise>
						        <xsl:copy-of select="IsToBePrinted"/>
					        </xsl:otherwise>
				        </xsl:choose>
				        <xsl:copy-of select="Memo"/>
					</BillPaymentCheckRet>
			  	</AFXInfo>
			</TxnVoidRq>
		</xsl:when>
        <xsl:otherwise> 
		    <BillPaymentCheckModRq>
		      <xsl:attribute name="requestID">
			  	<!-- Get the requestId from the parent element -->
		        <xsl:value-of select="..//@requestID"/>
		      </xsl:attribute>
		      <BillPaymentCheckMod>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
			    	<xsl:copy-of select="PayeeEntityRef"/>
			  	</AFXInfo>
		        <xsl:copy-of select="EditSequence"/>
		        <xsl:copy-of select="TxnDate"/>
		        <xsl:copy-of select="BankAccountRef"/>
			    <xsl:copy-of select="Amount"/>
		        <xsl:choose>
			   		<xsl:when test="RefNumber">
				        <xsl:copy-of select="RefNumber"/>
			        </xsl:when>
			        <xsl:otherwise>
				        <xsl:copy-of select="IsToBePrinted"/>
			        </xsl:otherwise>
		        </xsl:choose>
		        <xsl:copy-of select="Memo"/>
		        <xsl:apply-templates select="AppliedToTxnRet">
					<xsl:with-param name="mod" select="1" />
				</xsl:apply-templates>
		      </BillPaymentCheckMod>
		    </BillPaymentCheckModRq>
         </xsl:otherwise> 
    </xsl:choose>  	
  </xsl:template>

  <xsl:template match="BillPaymentCreditCardQueryRs/BillPaymentCreditCardRet">
    <BillPaymentCreditCardAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <BillPaymentCreditCardAdd>
	    <!-- TxnID is not part of the BillPaymentCreditCard Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
	    	<xsl:copy-of select="Amount"/>
	  	</AFXInfo>
        <xsl:copy-of select="PayeeEntityRef"/>
        <xsl:copy-of select="APAccountRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="CreditCardAccountRef"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="Memo"/>
        <xsl:apply-templates select="AppliedToTxnRet"/>
      </BillPaymentCreditCardAdd>
    </BillPaymentCreditCardAddRq>
  </xsl:template>

  <xsl:template match="BuildAssemblyQueryRs/BuildAssemblyRet">
    <BuildAssemblyAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <BuildAssemblyAdd>
	    <!-- TxnID is not part of the BuildAssembly Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
	  	</AFXInfo>
        <xsl:copy-of select="ItemInventoryAssemblyRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="Memo"/>
        <xsl:copy-of select="QuantityToBuild"/>
      </BuildAssemblyAdd>
    </BuildAssemblyAddRq>
  </xsl:template>

  <xsl:template match="ChargeQueryRs/ChargeRet">
    <ChargeAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ChargeAdd>
	    <!-- TxnID is not part of the Charge Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
	    	<xsl:copy-of select="Amount"/>
	  	</AFXInfo>
        <xsl:call-template name="ChargeDetails"/>
      </ChargeAdd>
    </ChargeAddRq>
  </xsl:template>

  <!-- Mod responses have a proprietary mod attribute set to 1 in the *Ret element -->
  <xsl:template match="ChargeQueryRs/ChargeRet[@mod='1']">

    <xsl:choose>
		<xsl:when test="Amount = '0.00' and starts-with(Desc, 'VOID:')">
			<TxnVoidRq>
				<TxnVoidType>Charge</TxnVoidType>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
					<ChargeRet>
				    	<xsl:copy-of select="Amount"/>
				        <xsl:call-template name="ChargeDetails"/>
					</ChargeRet>
			  	</AFXInfo>
			</TxnVoidRq>
		</xsl:when>
        <xsl:otherwise> 
		    <ChargeModRq>
		      <xsl:attribute name="requestID">
			  	<!-- Get the requestId from the parent element -->
		        <xsl:value-of select="..//@requestID"/>
		      </xsl:attribute>
		      <ChargeMod>
		        <xsl:copy-of select="TxnID"/>
			  	<AFXInfo>
			    	<xsl:copy-of select="Amount"/>
			  	</AFXInfo>
		        <xsl:copy-of select="EditSequence"/>
		        <xsl:call-template name="ChargeDetails"/>
		      </ChargeMod>
		    </ChargeModRq>
        </xsl:otherwise> 
    </xsl:choose>  	

  </xsl:template>

  <xsl:template name="ChargeDetails">
        <xsl:copy-of select="CustomerRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="ItemRef"/>
        <xsl:copy-of select="Quantity"/>
        <xsl:copy-of select="Rate"/>
        <xsl:copy-of select="Amount"/>
        <xsl:copy-of select="Desc"/>
        <xsl:copy-of select="ARAccountRef"/>
        <xsl:copy-of select="ClassRef"/>
        <xsl:copy-of select="BilledDate"/>
        <xsl:copy-of select="DueDate"/>
  </xsl:template>

  <xsl:template match="DateDrivenTermsQueryRs/DateDrivenTermsRet">
    <DateDrivenTermsAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <DateDrivenTermsAdd>
	    <!-- ListID is not part of the DateDrivenTerms Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="DayOfMonthDue"/>
        <xsl:copy-of select="DueNextMonthDays"/>
        <xsl:copy-of select="DiscountDayOfMonth"/>
        <xsl:copy-of select="DiscountPct"/>
      </DateDrivenTermsAdd>
    </DateDrivenTermsAddRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemDiscountRet | ItemDiscountQueryRs/ItemDiscountRet">
    <ItemDiscountAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemDiscountAdd>
	    <!-- ListID is not part of the ItemDiscount Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ParentRef"/>
        <xsl:copy-of select="ItemDesc"/>
        <xsl:copy-of select="SalesTaxCodeRef"/>
        <xsl:copy-of select="DiscountRate"/>
        <xsl:copy-of select="DiscountRatePercent"/>
        <xsl:copy-of select="AccountRef"/>
      </ItemDiscountAdd>
    </ItemDiscountAddRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemDiscountRet[@mod='1'] | ItemDiscountQueryRs/ItemDiscountRet[@mod='1']">
    <ItemDiscountModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemDiscountMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
		<xsl:choose>
		  <xsl:when test="ParentRef">
		    <xsl:copy-of select="ParentRef"/>
		  </xsl:when>
          <xsl:otherwise>
            <ParentRef>
			  <ListID></ListID>
            </ParentRef>
          </xsl:otherwise> 
 		</xsl:choose>
        <xsl:copy-of select="ItemDesc"/>
        <xsl:copy-of select="SalesTaxCodeRef"/>
        <xsl:copy-of select="DiscountRate"/>
        <xsl:copy-of select="DiscountRatePercent"/>
      </ItemDiscountMod>
    </ItemDiscountModRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemFixedAssetRet | ItemFixedAssetQueryRs/ItemFixedAssetRet">
    <ItemFixedAssetAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemFixedAssetAdd>
	    <!-- ListID is not part of the ItemFixedAsset Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:call-template name="ItemFixedAssetDetails"/>
      </ItemFixedAssetAdd>
    </ItemFixedAssetAddRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemFixedAssetRet[@mod='1'] | ItemFixedAssetQueryRs/ItemFixedAssetRet[@mod='1']">
    <ItemFixedAssetModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemFixedAssetMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:call-template name="ItemFixedAssetModDetails"/>
      </ItemFixedAssetMod>
    </ItemFixedAssetModRq>
  </xsl:template>

  <xsl:template name="ItemFixedAssetDetails">
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="AcquiredAs"/>
        <xsl:copy-of select="PurchaseDesc"/>
        <xsl:copy-of select="PurchaseDate"/>
        <xsl:copy-of select="PurchaseCost"/>
        <xsl:copy-of select="VendorOrPayeeName"/>
        <xsl:copy-of select="AssetAccountRef"/>
        <xsl:copy-of select="FixedAssetSalesInfo"/>
        <xsl:copy-of select="AssetDesc"/>
        <xsl:copy-of select="Location"/>
        <xsl:copy-of select="PONumber"/>
        <xsl:copy-of select="SerialNumber"/>
        <xsl:copy-of select="WarrantyExpDate"/>
        <xsl:copy-of select="Notes"/>
        <xsl:copy-of select="AssetNumber"/>
        <xsl:copy-of select="CostBasis"/>
        <xsl:copy-of select="YearEndAccumulatedDepreciation"/>
        <xsl:copy-of select="YearEndBookValue"/>
  </xsl:template>

  <xsl:template name="ItemFixedAssetModDetails">
    <xsl:copy-of select="Name"/>
    <xsl:copy-of select="IsActive"/>
    <xsl:copy-of select="AcquiredAs"/>
    <xsl:copy-of select="PurchaseDesc"/>
    <xsl:copy-of select="PurchaseDate"/>
    <xsl:copy-of select="PurchaseCost"/>
    <xsl:copy-of select="VendorOrPayeeName"/>
    <xsl:copy-of select="AssetAccountRef"/>
    <xsl:if test="FixedAssetSalesInfo">
      <FixedAssetSalesInfoMod>
        <xsl:copy-of select="FixedAssetSalesInfo/SalesDesc"/>
        <xsl:copy-of select="FixedAssetSalesInfo/SalesDate"/>
        <xsl:copy-of select="FixedAssetSalesInfo/SalesPrice"/>
        <xsl:copy-of select="FixedAssetSalesInfo/SalesExpense"/>
      </FixedAssetSalesInfoMod>
      </xsl:if>
    <xsl:copy-of select="AssetDesc"/>
    <xsl:copy-of select="Location"/>
    <xsl:copy-of select="PONumber"/>
    <xsl:copy-of select="SerialNumber"/>
    <xsl:copy-of select="WarrantyExpDate"/>
    <xsl:copy-of select="Notes"/>
    <xsl:copy-of select="AssetNumber"/>
    <xsl:copy-of select="CostBasis"/>
    <xsl:copy-of select="YearEndAccumulatedDepreciation"/>
    <xsl:copy-of select="YearEndBookValue"/>
  </xsl:template>


  <xsl:template match="ItemQueryRs/ItemGroupRet | ItemGroupQueryRs/ItemGroupRet">
    <ItemGroupAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemGroupAdd>
	    <!-- ListID is not part of the ItemGroup Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ItemDesc"/>
        <xsl:copy-of select="IsPrintItemsInGroup"/>
        <xsl:copy-of select="ItemGroupLine"/>
      </ItemGroupAdd>
    </ItemGroupAddRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemGroupRet[@mod='1'] | ItemGroupQueryRs/ItemGroupRet[@mod='1']">
    <ItemGroupModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemGroupMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ItemDesc"/>
        <xsl:copy-of select="IsPrintItemsInGroup"/>
        <xsl:copy-of select="ClearItemsInGroup"/>
        <xsl:copy-of select="ItemGroupLine"/>
      </ItemGroupMod>
    </ItemGroupModRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemInventoryRet | ItemInventoryQueryRs/ItemInventoryRet">
    <ItemInventoryAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemInventoryAdd>
	    <!-- ListID is not part of the ItemInventory Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ParentRef"/>
        <xsl:copy-of select="SalesTaxCodeRef"/>
        <xsl:copy-of select="SalesDesc"/>
        <xsl:copy-of select="SalesPrice"/>
        <xsl:copy-of select="IncomeAccountRef"/>
        <xsl:copy-of select="PurchaseDesc"/>
        <xsl:copy-of select="PurchaseCost"/>
        <xsl:copy-of select="COGSAccountRef"/>
        <xsl:copy-of select="PrefVendorRef"/>
        <xsl:copy-of select="AssetAccountRef"/>
        <xsl:copy-of select="ReorderPoint"/>
        <xsl:copy-of select="QuantityOnHand"/>
      </ItemInventoryAdd>
    </ItemInventoryAddRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemInventoryRet[@mod='1'] | ItemInventoryQueryRs/ItemInventoryRet[@mod='1']">
    <ItemInventoryModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemInventoryMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
 		<xsl:choose>
		  <xsl:when test="ParentRef">
		    <xsl:copy-of select="ParentRef"/>
		  </xsl:when>
          <xsl:otherwise>
            <ParentRef>
			  <ListID></ListID>
            </ParentRef>
          </xsl:otherwise> 
 		</xsl:choose>
		<xsl:copy-of select="SalesTaxCodeRef"/>
        <xsl:copy-of select="SalesDesc"/>
        <xsl:copy-of select="SalesPrice"/>
        <xsl:copy-of select="PurchaseDesc"/>
        <xsl:copy-of select="PurchaseCost"/>
        <xsl:copy-of select="COGSAccountRef"/>
        <xsl:copy-of select="PrefVendorRef"/>
        <xsl:copy-of select="AssetAccountRef"/>
        <xsl:copy-of select="ReorderPoint"/>
      </ItemInventoryMod>
    </ItemInventoryModRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemInventoryAssemblyRet | ItemInventoryAssemblyQueryRs/ItemInventoryAssemblyRet">
    <ItemInventoryAssemblyAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemInventoryAssemblyAdd>
	    <!-- ListID is not part of the ItemInventoryAssembly Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ParentRef"/>
        <xsl:copy-of select="SalesTaxCodeRef"/>
        <xsl:copy-of select="SalesDesc"/>
        <xsl:copy-of select="SalesPrice"/>
        <xsl:copy-of select="IncomeAccountRef"/>
        <xsl:copy-of select="PurchaseDesc"/>
        <xsl:copy-of select="PurchaseCost"/>
        <xsl:copy-of select="COGSAccountRef"/>
        <xsl:copy-of select="PrefVendorRef"/>
        <xsl:copy-of select="AssetAccountRef"/>
        <xsl:copy-of select="BuildPoint"/>
        <xsl:copy-of select="QuantityOnHand"/>
        <xsl:copy-of select="ItemInventoryAssemblyLine"/>
      </ItemInventoryAssemblyAdd>
    </ItemInventoryAssemblyAddRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemInventoryAssemblyRet[@mod='1'] | ItemInventoryAssemblyQueryRs/ItemInventoryAssemblyRet[@mod='1']">
    <ItemInventoryAssemblyModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemInventoryAssemblyMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
		<xsl:choose>
		  <xsl:when test="ParentRef">
		    <xsl:copy-of select="ParentRef"/>
		  </xsl:when>
          <xsl:otherwise>
            <ParentRef>
			  <ListID></ListID>
            </ParentRef>
          </xsl:otherwise> 
 		</xsl:choose>
        <xsl:copy-of select="SalesTaxCodeRef"/>
        <xsl:copy-of select="SalesDesc"/>
        <xsl:copy-of select="SalesPrice"/>
        <xsl:copy-of select="PurchaseDesc"/>
        <xsl:copy-of select="PurchaseCost"/>
        <xsl:copy-of select="COGSAccountRef"/>
        <xsl:copy-of select="PrefVendorRef"/>
        <xsl:copy-of select="AssetAccountRef"/>
        <xsl:copy-of select="BuildPoint"/>
        <xsl:copy-of select="ClearItemsInGroup"/>
        <xsl:copy-of select="ItemInventoryAssemblyLine"/>
      </ItemInventoryAssemblyMod>
    </ItemInventoryAssemblyModRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemOtherChargeRet | ItemOtherChargeQueryRs/ItemOtherChargeRet">
    <ItemOtherChargeAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemOtherChargeAdd>
	    <!-- ListID is not part of the ItemOtherCharge Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ParentRef"/>
        <xsl:copy-of select="SalesTaxCodeRef"/>
        <xsl:copy-of select="SalesOrPurchase"/>
        <xsl:copy-of select="SalesAndPurchase"/>
      </ItemOtherChargeAdd>
    </ItemOtherChargeAddRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemOtherChargeRet[@mod='1'] | ItemOtherChargeQueryRs/ItemOtherChargeRet[@mod='1']">
    <ItemOtherChargeModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemOtherChargeMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
		<xsl:choose>
		  <xsl:when test="ParentRef">
		    <xsl:copy-of select="ParentRef"/>
		  </xsl:when>
          <xsl:otherwise>
            <ParentRef>
			  <ListID></ListID>
            </ParentRef>
          </xsl:otherwise> 
 		</xsl:choose>
        <xsl:copy-of select="SalesTaxCodeRef"/>
        <xsl:apply-templates select="SalesOrPurchase"/>
        <xsl:apply-templates select="SalesAndPurchase"/>
      </ItemOtherChargeMod>
    </ItemOtherChargeModRq>
  </xsl:template>


  <xsl:template match="ItemQueryRs/ItemNonInventoryRet | ItemNonInventoryQueryRs/ItemNonInventoryRet">
    <ItemNonInventoryAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemNonInventoryAdd>
	    <!-- ListID is not part of the ItemNonInventory Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ParentRef"/>
        <xsl:copy-of select="SalesTaxCodeRef"/>
        <xsl:copy-of select="SalesOrPurchase"/>
        <xsl:copy-of select="SalesAndPurchase"/>
      </ItemNonInventoryAdd>
    </ItemNonInventoryAddRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemNonInventoryRet[@mod='1'] | ItemNonInventoryQueryRs/ItemNonInventoryRet[@mod='1']">
    <ItemNonInventoryModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemNonInventoryMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
		<xsl:choose>
		  <xsl:when test="ParentRef">
		    <xsl:copy-of select="ParentRef"/>
		  </xsl:when>
          <xsl:otherwise>
            <ParentRef>
			  <ListID></ListID>
            </ParentRef>
          </xsl:otherwise> 
 		</xsl:choose>
        <xsl:copy-of select="SalesTaxCodeRef"/>
        <xsl:apply-templates select="SalesOrPurchase"/>
        <xsl:apply-templates select="SalesAndPurchase"/>
      </ItemNonInventoryMod>
    </ItemNonInventoryModRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemServiceRet | ItemServiceQueryRs/ItemServiceRet">
    <ItemServiceAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemServiceAdd>
	    <!-- ListID is not part of the ItemService Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ParentRef"/>
        <xsl:copy-of select="SalesTaxCodeRef"/>
        <xsl:copy-of select="SalesOrPurchase"/>
        <xsl:copy-of select="SalesAndPurchase"/>
      </ItemServiceAdd>
    </ItemServiceAddRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemServiceRet[@mod='1'] | ItemServiceQueryRs/ItemServiceRet[@mod='1']">
    <ItemServiceModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemServiceMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
		<xsl:choose>
		  <xsl:when test="ParentRef">
		    <xsl:copy-of select="ParentRef"/>
		  </xsl:when>
          <xsl:otherwise>
            <ParentRef>
			  <ListID></ListID>
            </ParentRef>
          </xsl:otherwise> 
 		</xsl:choose>
        <xsl:copy-of select="SalesTaxCodeRef"/>
        <xsl:apply-templates select="SalesOrPurchase"/>
        <xsl:apply-templates select="SalesAndPurchase"/>
      </ItemServiceMod>
    </ItemServiceModRq>
  </xsl:template>

  <xsl:template match="SalesOrPurchase">
  	<SalesOrPurchaseMod>
	    <xsl:copy-of select="Desc"/>
	    <xsl:copy-of select="Price"/>
	    <xsl:copy-of select="PricePercent"/>
  	</SalesOrPurchaseMod>
  </xsl:template>

  <xsl:template match="SalesAndPurchase">
  	<SalesAndPurchaseMod>
	    <xsl:copy-of select="SalesDesc"/>
	    <xsl:copy-of select="SalesPrice"/>
	    <xsl:copy-of select="PurchaseDesc"/>
	    <xsl:copy-of select="PurchaseCost"/>
	    <xsl:copy-of select="PrefVendorRef"/>
  	</SalesAndPurchaseMod>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemSalesTaxGroupRet | ItemSalesTaxGroupQueryRs/ItemSalesTaxGroupRet">
    <ItemSalesTaxGroupAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemSalesTaxGroupAdd>
	    <!-- ListID is not part of the ItemSalesTaxGroup Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:call-template name="ItemSalesTaxGroupDetails"/>
      </ItemSalesTaxGroupAdd>
    </ItemSalesTaxGroupAddRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemSalesTaxGroupRet[@mod='1'] | ItemSalesTaxGroupQueryRs/ItemSalesTaxGroupRet[@mod='1']">
    <ItemSalesTaxGroupModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemSalesTaxGroupMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:call-template name="ItemSalesTaxGroupDetails"/>
      </ItemSalesTaxGroupMod>
    </ItemSalesTaxGroupModRq>
  </xsl:template>

  <xsl:template name="ItemSalesTaxGroupDetails">
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ItemDesc"/>
        <xsl:copy-of select="ItemSalesTaxRef"/>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemSalesTaxRet | ItemSalesTaxQueryRs/ItemSalesTaxRet">
    <ItemSalesTaxAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemSalesTaxAdd>
	    <!-- ListID is not part of the ItemSalesTax Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:call-template name="ItemSalesTaxDetails"/>
      </ItemSalesTaxAdd>
    </ItemSalesTaxAddRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemSalesTaxRet[@mod='1'] | ItemSalesTaxQueryRs/ItemSalesTaxRet[@mod='1']">
    <ItemSalesTaxModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemSalesTaxMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:call-template name="ItemSalesTaxDetails"/>
      </ItemSalesTaxMod>
    </ItemSalesTaxModRq>
  </xsl:template>

  <xsl:template name="ItemSalesTaxDetails">
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ItemDesc"/>
        <xsl:copy-of select="TaxRate"/>
        <xsl:copy-of select="TaxVendorRef"/>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemSubtotalRet | ItemSubtotalQueryRs/ItemSubtotalRet">
    <ItemSubtotalAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemSubtotalAdd>
	    <!-- ListID is not part of the ItemSubtotal Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ItemDesc"/>
      </ItemSubtotalAdd>
    </ItemSubtotalAddRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemSubtotalRet[@mod='1'] | ItemSubtotalQueryRs/ItemSubtotalRet[@mod='1']">
    <ItemSubtotalModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemSubtotalMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ItemDesc"/>
      </ItemSubtotalMod>
    </ItemSubtotalModRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemPaymentRet | ItemPaymentQueryRs/ItemPaymentRet">
    <ItemPaymentAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemPaymentAdd>
	    <!-- ListID is not part of the ItemPayment Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:call-template name="ItemPaymentDetails"/>
      </ItemPaymentAdd>
    </ItemPaymentAddRq>
  </xsl:template>

  <xsl:template match="ItemQueryRs/ItemPaymentRet[@mod='1'] | ItemPaymentQueryRs/ItemPaymentRet[@mod='1']">
    <ItemPaymentModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemPaymentMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:call-template name="ItemPaymentDetails"/>
      </ItemPaymentMod>
    </ItemPaymentModRq>
  </xsl:template>

  <xsl:template name="ItemPaymentDetails">
    <xsl:copy-of select="Name"/>
    <xsl:copy-of select="IsActive"/>
    <xsl:copy-of select="ItemDesc"/>
    <xsl:copy-of select="DepositToAccountRef"/>
    <xsl:copy-of select="PaymentMethodRef"/>
  </xsl:template>

  <xsl:template match="ItemReceiptQueryRs/ItemReceiptRet">
    <ItemReceiptAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemReceiptAdd>
	    <!-- TxnID is not part of the Invoice Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>
	    	<xsl:copy-of select="TxnID"/>
	    	<xsl:copy-of select="TotalAmount"/>
	  	</AFXInfo>
        <xsl:copy-of select="VendorRef"/>
        <xsl:copy-of select="APAccountRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="Memo"/>
        <xsl:apply-templates select="LinkedTxn"/>
        <xsl:apply-templates select="ExpenseLineRet"/>
		<xsl:apply-templates select="ItemLineRet | ItemGroupLineRet"/>
      </ItemReceiptAdd>
    </ItemReceiptAddRq>
  </xsl:template>

  <xsl:template match="ItemReceiptQueryRs/ItemReceiptRet[@mod='1']">
    <ItemReceiptModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ItemReceiptMod>
    	<xsl:copy-of select="TxnID"/>
	  	<AFXInfo>
	    	<xsl:copy-of select="TotalAmount"/>
	  	</AFXInfo>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:copy-of select="VendorRef"/>
        <xsl:copy-of select="APAccountRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <xsl:copy-of select="Memo"/>
        <xsl:copy-of select="ClearExpenseLines"/>
        <xsl:apply-templates select="ExpenseLineRet">
			<xsl:with-param name="mod" select="1" />
		</xsl:apply-templates>
        <xsl:copy-of select="ClearItemLines"/>
        <xsl:apply-templates select="ItemLineRet | ItemGroupLineRet">
			<xsl:with-param name="mod" select="1" />
		</xsl:apply-templates>
      </ItemReceiptMod>
    </ItemReceiptModRq>
  </xsl:template>

  <xsl:template match="CustomerTypeQueryRs/CustomerTypeRet">
    <CustomerTypeAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <CustomerTypeAdd>
	    <!-- ListID is not part of the CustomerType Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ParentRef"/>
      </CustomerTypeAdd>
    </CustomerTypeAddRq>
  </xsl:template>

  <!-- Template which matches the VendorTypeRet element -->
  <xsl:template match="VendorTypeQueryRs/VendorTypeRet">
    <VendorTypeAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <VendorTypeAdd>
	    <!-- ListID is not part of the VendorType Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ParentRef"/>
      </VendorTypeAdd>
    </VendorTypeAddRq>
  </xsl:template>

  <!-- Template which matches the JobTypeRet element -->
  <xsl:template match="JobTypeQueryRs/JobTypeRet">
    <JobTypeAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <JobTypeAdd>
	    <!-- ListID is not part of the JobType Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ParentRef"/>
      </JobTypeAdd>
    </JobTypeAddRq>
  </xsl:template>

  <!-- Template which matches the StandardTermsRet element -->
  <xsl:template match="StandardTermsQueryRs/StandardTermsRet">
    <StandardTermsAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <StandardTermsAdd>
	    <!-- ListID is not part of the StandardTerms Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="StdDueDays"/>
        <xsl:copy-of select="StdDiscountDays"/>
        <xsl:copy-of select="DiscountPct"/>
      </StandardTermsAdd>
    </StandardTermsAddRq>
  </xsl:template>

  <!-- Template which matches the PaymentMethodRet element -->
  <xsl:template match="PaymentMethodQueryRs/PaymentMethodRet">
    <PaymentMethodAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <PaymentMethodAdd>
	    <!-- ListID is not part of the PaymentMethod Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
      </PaymentMethodAdd>
    </PaymentMethodAddRq>
  </xsl:template>

  <!-- Template which matches the ShipMethodRet element -->
  <xsl:template match="ShipMethodQueryRs/ShipMethodRet">
    <ShipMethodAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ShipMethodAdd>
	    <!-- ListID is not part of the ShipMethod Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
      </ShipMethodAdd>
    </ShipMethodAddRq>
  </xsl:template>

  <!-- Template which matches the CustomerMsgRet element -->
  <xsl:template match="CustomerMsgQueryRs/CustomerMsgRet">
    <CustomerMsgAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <CustomerMsgAdd>
	    <!-- ListID is not part of the CustomerMsg Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
      </CustomerMsgAdd>
    </CustomerMsgAddRq>
  </xsl:template>

  <!-- Template which matches the ClassRet element -->
  <xsl:template match="ClassQueryRs/ClassRet">
    <ClassAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ClassAdd>
	    <!-- ListID is not part of the class Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="ParentRef"/>
      </ClassAdd>
    </ClassAddRq>
  </xsl:template>

  <!-- Template which matches the SalesRepRet element -->
  <xsl:template match="SalesRepQueryRs/SalesRepRet">
    <SalesRepAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <SalesRepAdd>
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:call-template name="SalesRepDetails"/>
      </SalesRepAdd>
    </SalesRepAddRq>
  </xsl:template>

  <xsl:template match="SalesRepQueryRs/SalesRepRet[@mod='1']">
    <SalesRepModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <SalesRepMod>
       	<xsl:copy-of select="ListID"/>
        <xsl:copy-of select="EditSequence"/>
        <xsl:call-template name="SalesRepDetails"/>
      </SalesRepMod>
    </SalesRepModRq>
  </xsl:template>

  <xsl:template name="SalesRepDetails">
    <xsl:copy-of select="Initial"/>
    <xsl:copy-of select="IsActive"/>
    <xsl:copy-of select="SalesRepEntityRef"/>
  </xsl:template>

  <!-- Template which matches the SalesTaxCodeRet element -->
  <xsl:template match="SalesTaxCodeQueryRs/SalesTaxCodeRet">
    <SalesTaxCodeAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <SalesTaxCodeAdd>
	    <!-- ListID is not part of the SalesTaxCode Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="IsTaxable"/>
        <xsl:copy-of select="Desc"/>
      </SalesTaxCodeAdd>
    </SalesTaxCodeAddRq>
  </xsl:template>

  <!-- Template which matches the ToDoRet element -->
  <xsl:template match="ToDoQueryRs/ToDoRet">
    <ToDoAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ToDoAdd>
	    <!-- ListID is not part of the ToDo Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Notes"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="IsDone"/>
        <xsl:copy-of select="ReminderDate"/>
      </ToDoAdd>
    </ToDoAddRq>
  </xsl:template>

  <!-- Template which matches the PriceLevelRet element -->
  <xsl:template match="PriceLevelQueryRs/PriceLevelRet">
    <PriceLevelAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <PriceLevelAdd>
	    <!-- ListID is not part of the PriceLevel Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="PriceLevelFixedPercentage"/>
        <xsl:apply-templates select="PriceLevelPerItemRet"/>
      </PriceLevelAdd>
    </PriceLevelAddRq>
  </xsl:template>

  <xsl:template match="PriceLevelQueryRs/PriceLevelRet[@mod='1']">
    <PriceLevelModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <PriceLevelMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="PriceLevelFixedPercentage"/>
        <xsl:apply-templates select="PriceLevelPerItemRet"/>
      </PriceLevelMod>
    </PriceLevelModRq>
  </xsl:template>


  <!-- Template which matches the PriceLevelPerItemRet subcomponent of PriceLevelRet element -->
  <xsl:template match="PriceLevelPerItemRet">
    <PriceLevelPerItem>
      <xsl:copy-of select="ItemRef"/>
      <xsl:copy-of select="CustomPrice"/>
      <xsl:copy-of select="CustomPricePercent"/>
    </PriceLevelPerItem>
  </xsl:template>

  <!-- Template which matches the OtherNameRet element -->
  <xsl:template match="OtherNameQueryRs/OtherNameRet">
    <OtherNameAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <OtherNameAdd>
	    <!-- ListID is not part of the OtherName Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:call-template name="OtherNameModDetails"/>
      </OtherNameAdd>
    </OtherNameAddRq>
  </xsl:template>


  <xsl:template match="OtherNameQueryRs/OtherNameRet[@mod='1']">
    <OtherNameModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <OtherNameMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:call-template name="OtherNameModDetails"/>
      </OtherNameMod>
    </OtherNameModRq>
  </xsl:template>

  <xsl:template name="OtherNameModDetails">
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="CompanyName"/>
        <xsl:copy-of select="Salutation"/>
        <xsl:copy-of select="FirstName"/>
        <xsl:copy-of select="MiddleName"/>
        <xsl:copy-of select="LastName"/>
        <xsl:copy-of select="OtherNameAddress"/>
        <xsl:copy-of select="Phone"/>
        <xsl:copy-of select="AltPhone"/>
        <xsl:copy-of select="Fax"/>
        <xsl:copy-of select="Email"/>
        <xsl:copy-of select="Contact"/>
        <xsl:copy-of select="AltContact"/>
        <xsl:copy-of select="AccountNumber"/>
        <xsl:copy-of select="Notes"/>
  </xsl:template>

  <!-- Template which matches the CustomerRet element -->
  <xsl:template match="CustomerQueryRs/CustomerRet">
    <CustomerAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <CustomerAdd>
	    <!-- ListID is not part of the Customer Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:call-template name="CustomerDetails">
			<xsl:with-param name="mod" select="0" />
		</xsl:call-template>
      </CustomerAdd>
    </CustomerAddRq>
  </xsl:template>

  <xsl:template match="CustomerQueryRs/CustomerRet[@mod='1']">
    <CustomerModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <CustomerMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:call-template name="CustomerDetails"/>
      </CustomerMod>
    </CustomerModRq>
  </xsl:template>

  <xsl:template name="CustomerDetails">

		<xsl:param name="mod" select="1"/>

        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
 		<xsl:choose>
		  <xsl:when test="ParentRef">
		    <xsl:copy-of select="ParentRef"/>
		  </xsl:when>
          <xsl:otherwise>
			<xsl:if test="$mod='1'">
	            <ParentRef>
				  <ListID></ListID>
	            </ParentRef>
			</xsl:if>
          </xsl:otherwise> 
 		</xsl:choose>
        <xsl:copy-of select="CompanyName"/>
        <xsl:copy-of select="Salutation"/>
        <xsl:copy-of select="FirstName"/>
        <xsl:copy-of select="MiddleName"/>
        <xsl:copy-of select="LastName"/>
        <xsl:copy-of select="Suffix"/>
        <xsl:copy-of select="BillAddress"/>
        <xsl:copy-of select="ShipAddress"/>
        <xsl:copy-of select="PrintAs"/>
        <xsl:copy-of select="Phone"/>
        <xsl:copy-of select="Mobile"/>
        <xsl:copy-of select="Pager"/>
        <xsl:copy-of select="AltPhone"/>
        <xsl:copy-of select="Fax"/>
        <xsl:copy-of select="Email"/>
        <xsl:copy-of select="Contact"/>
        <xsl:copy-of select="AltContact"/>
        <xsl:copy-of select="CustomerTypeRef"/>
        <xsl:copy-of select="TermsRef"/>
        <xsl:copy-of select="SalesRepRef"/>
        <xsl:copy-of select="SalesTaxCodeRef"/>
        <xsl:copy-of select="ItemSalesTaxRef"/>
        <xsl:copy-of select="ResaleNumber"/>
        <xsl:copy-of select="AccountNumber"/>
        <xsl:copy-of select="CreditLimit"/>
        <xsl:copy-of select="PreferredPaymentMethodRef"/>
        <xsl:copy-of select="CreditCardInfo"/> 
        <xsl:copy-of select="JobStatus"/>
        <xsl:copy-of select="JobStartDate"/>
        <xsl:copy-of select="JobProjectedEndDate"/>
        <xsl:copy-of select="JobEndDate"/>
        <xsl:copy-of select="JobDesc"/>
        <xsl:copy-of select="JobTypeRef"/>
        <xsl:copy-of select="Notes"/>
        <xsl:copy-of select="IsStatementWithParent"/>
        <xsl:copy-of select="DeliveryMethod"/>
        <xsl:copy-of select="PriceLevelRef"/>
  </xsl:template>

  <!-- Template which matches the VendorRet element -->
  <xsl:template match="VendorQueryRs/VendorRet">
    <VendorAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <VendorAdd>
	    <!-- ListID is not part of the Vendor Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
		</AFXInfo>
        <xsl:call-template name="VendorDetails"/>
      </VendorAdd>
    </VendorAddRq>
  </xsl:template>

  <xsl:template match="VendorQueryRs/VendorRet[@mod='1']">
    <VendorModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <VendorMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
        <xsl:call-template name="VendorDetails"/>
      </VendorMod>
    </VendorModRq>
  </xsl:template>

  <xsl:template name="VendorDetails">
        <xsl:copy-of select="Name"/>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="CompanyName"/>
        <xsl:copy-of select="Salutation"/>
        <xsl:copy-of select="FirstName"/>
        <xsl:copy-of select="MiddleName"/>
        <xsl:copy-of select="LastName"/>
        <xsl:copy-of select="Suffix"/>
        <xsl:copy-of select="VendorAddress"/>
        <xsl:copy-of select="Phone"/>
        <xsl:copy-of select="Mobile"/>
        <xsl:copy-of select="Pager"/>
        <xsl:copy-of select="AltPhone"/>
        <xsl:copy-of select="Fax"/>
        <xsl:copy-of select="Email"/>
        <xsl:copy-of select="Contact"/>
        <xsl:copy-of select="AltContact"/>
        <xsl:copy-of select="NameOnCheck"/>
        <xsl:copy-of select="AccountNumber"/>
        <xsl:copy-of select="Notes"/>
        <xsl:copy-of select="VendorTypeRef"/>
        <xsl:copy-of select="TermsRef"/>
        <xsl:copy-of select="CreditLimit"/>
        <xsl:copy-of select="VendorTaxIdent"/>
        <xsl:copy-of select="IsVendorEligibleFor1099"/>
  </xsl:template>

  <!-- Template which matches the EmployeeRet element -->
  <xsl:template match="EmployeeQueryRs/EmployeeRet">
    <EmployeeAddRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <EmployeeAdd>
	    <!-- ListID is not part of the Employee Add request but needed while
			 importing accountant changes on the client side. -->
	  	<AFXInfo>	
        	<xsl:copy-of select="ListID"/>
			<Name>
    			<xsl:if test="FirstName">
	        		<xsl:value-of select="FirstName"/> 
					<xsl:text> </xsl:text>
				</xsl:if> 
    			<xsl:if test="MiddleName">
					<xsl:value-of select="MiddleName"/>
					<xsl:text> </xsl:text>
				</xsl:if> 
    			<xsl:if test="LastName">
	        		<xsl:value-of select="LastName"/>
				</xsl:if> 
			</Name>
		</AFXInfo>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="Salutation"/>
        <xsl:copy-of select="FirstName"/>
        <xsl:copy-of select="MiddleName"/>
        <xsl:copy-of select="LastName"/>
        <xsl:copy-of select="Suffix"/>
        <xsl:copy-of select="EmployeeAddress"/>
        <xsl:copy-of select="PrintAs"/>
        <xsl:copy-of select="Phone"/>
        <xsl:copy-of select="Mobile"/>
        <xsl:copy-of select="Pager"/>
        <xsl:copy-of select="PagerPIN"/>
        <xsl:copy-of select="AltPhone"/>
        <xsl:copy-of select="Fax"/>
        <xsl:copy-of select="SSN"/>
        <xsl:copy-of select="Email"/>
        <xsl:copy-of select="EmployeeType"/>
        <xsl:copy-of select="Gender"/>
        <xsl:copy-of select="HiredDate"/>
        <xsl:copy-of select="ReleasedDate"/>
        <xsl:copy-of select="BirthDate"/>
        <xsl:copy-of select="AccountNumber"/>
        <xsl:copy-of select="Notes"/>
        <xsl:copy-of select="EmployeePayrollInfo"/>
      </EmployeeAdd>
    </EmployeeAddRq>
  </xsl:template>

  <xsl:template match="EmployeeQueryRs/EmployeeRet[@mod='1']">
    <EmployeeModRq>
      <xsl:attribute name="requestID">
	  	<!-- Get the requestId from the parent element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <EmployeeMod>
       	<xsl:copy-of select="ListID"/>
       	<xsl:copy-of select="EditSequence"/>
	  	<AFXInfo>	
			<Name>
    			<xsl:if test="FirstName">
	        		<xsl:value-of select="FirstName"/> 
					<xsl:text> </xsl:text>
				</xsl:if> 
    			<xsl:if test="MiddleName">
					<xsl:value-of select="MiddleName"/>
					<xsl:text> </xsl:text>
				</xsl:if> 
    			<xsl:if test="LastName">
	        		<xsl:value-of select="LastName"/>
				</xsl:if> 
			</Name>
		</AFXInfo>
        <xsl:copy-of select="IsActive"/>
        <xsl:copy-of select="Salutation"/>
        <xsl:copy-of select="FirstName"/>
        <xsl:copy-of select="MiddleName"/>
        <xsl:copy-of select="LastName"/>
        <xsl:copy-of select="Suffix"/>
        <xsl:copy-of select="EmployeeAddress"/>
        <xsl:copy-of select="PrintAs"/>
        <xsl:copy-of select="Phone"/>
        <xsl:copy-of select="Mobile"/>
        <xsl:copy-of select="Pager"/>
        <xsl:copy-of select="PagerPIN"/>
        <xsl:copy-of select="AltPhone"/>
        <xsl:copy-of select="Fax"/>
        <xsl:copy-of select="Email"/>
        <xsl:copy-of select="BirthDate"/>
        <xsl:copy-of select="AccountNumber"/>
        <xsl:copy-of select="Notes"/>
        <xsl:call-template name="EmployeePayrollInfoModDetails"/>
      </EmployeeMod>
    </EmployeeModRq>
  </xsl:template>

  <xsl:template name="EmployeePayrollInfoModDetails">
  	<EmployeePayrollInfoMod>
        <xsl:copy-of select="PayPeriod"/>
        <xsl:copy-of select="ClassRef"/>
        <xsl:copy-of select="ClearEarnings"/>
        <xsl:copy-of select="Earnings"/>
        <xsl:copy-of select="UseTimeDataToCreatePaychecks"/>
        <xsl:copy-of select="SickHours"/>
        <xsl:copy-of select="VacationHours"/>
  	</EmployeePayrollInfoMod>
  </xsl:template>

  <xsl:template match="ARRefundCreditCardQueryRs/ARRefundCreditCardRet">
    <ARRefundCreditCardAddRq>
      <xsl:attribute name="requestID">
        <!-- Get the requestId from the parent InvoiceRs element -->
        <xsl:value-of select="..//@requestID"/>
      </xsl:attribute>
      <ARRefundCreditCardAdd>
        <xsl:copy-of select="CustomerRef"/>
        <xsl:copy-of select="RefundFromAccountRef"/>
        <xsl:copy-of select="ARAccountRef"/>
        <xsl:copy-of select="TxnDate"/>
        <xsl:copy-of select="RefNumber"/>
        <AFXInfo>
          <xsl:copy-of select="TotalAmount"/>
        </AFXInfo>
        <xsl:copy-of select="Address"/>
        <xsl:copy-of select="PaymentMethodRef"/>
        <xsl:copy-of select="Memo"/>
        <xsl:apply-templates select="RefundAppliedToTxnRet"/>
      </ARRefundCreditCardAdd>
      </ARRefundCreditCardAddRq>
</xsl:template>

  <xsl:template match="RefundAppliedToTxnRet">
  	<RefundAppliedToTxnAdd>
        <xsl:copy-of select="TxnID"/>
        <xsl:copy-of select="RefundAmount"/>
		<AFXInfo>
        	<xsl:copy-of select="TxnType"/>
        	<xsl:copy-of select="TxnDate"/>
        	<xsl:copy-of select="RefNumber"/>
        	<xsl:copy-of select="CreditRemaining"/>
		</AFXInfo>
  	</RefundAppliedToTxnAdd>

  </xsl:template>

  <!-- Generic template for transforming all transaction delete responses to 
  	   delete requests along with some proprietary elements -->
  <xsl:template match="TxnDelRq">
  	<TxnDelRq>
        <xsl:copy-of select="TxnDelType"/>
        <xsl:copy-of select="TxnID"/>
        <xsl:copy-of select="AFXInfo"/>
  	</TxnDelRq>
  </xsl:template>

  <!-- Generic template for transforming all list delete responses to 
  	   delete requests along with some proprietary elements -->
  <xsl:template match="ListDelRq">
  	<ListDelRq>
        <xsl:copy-of select="ListDelType"/>
        <xsl:copy-of select="ListID"/>
        <xsl:copy-of select="AFXInfo"/>
  	</ListDelRq>
  </xsl:template>

  <xsl:template name="TxnLineIdForMods">

	<xsl:param name="ItemGroupLineMod" select="0"/>

    <xsl:choose>
		<xsl:when test="@new='1' or $ItemGroupLineMod='1'">
			<TxnLineID>-1</TxnLineID>
			<AFXInfo>				
				<xsl:copy-of select="TxnLineID"/>
			</AFXInfo>	
	   	</xsl:when>
    	<xsl:otherwise>
			<xsl:copy-of select="TxnLineID"/>
    	</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet><!-- Stylus Studio meta-information - (c) 2004-2005. Progress Software Corporation. All rights reserved.
<metaInformation>
<scenarios ><scenario default="yes" name="res1" userelativepaths="yes" externalpreview="no" url="..\..\..\..\..\changes.xml" htmlbaseurl="" outputurl="" processortype="internal" useresolver="yes" profilemode="0" profiledepth="" profilelength="" urlprofilexml="" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext="" validateoutput="no" validator="internal" customvalidator=""/></scenarios><MapperMetaTag><MapperInfo srcSchemaPathIsRelative="yes" srcSchemaInterpretAsXML="no" destSchemaPath="" destSchemaRoot="" destSchemaPathIsRelative="yes" destSchemaInterpretAsXML="no"/><MapperBlockPosition></MapperBlockPosition><TemplateContext></TemplateContext><MapperFilter side="source"></MapperFilter></MapperMetaTag>
</metaInformation>
-->