<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:template match="/">
        <xsl:for-each select="//TranslatedData">
            <xsl:element name="TranslatedData">
                <xsl:attribute name="TranslationOutputFile">
                    <xsl:value-of select="@TranslationOutputFile"/>
                </xsl:attribute>
                <xsl:choose>
                    <xsl:when test="Details/@PrgID">
                        <xsl:copy-of select="Details"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:element name="Details">
                            <xsl:attribute name="PrgID">OECTrans.ImportTrans</xsl:attribute>
                            <xsl:for-each select="Details/@*">
                                <xsl:copy-of select="."/>
                            </xsl:for-each>
                            <xsl:for-each select="Details/*">
                                <xsl:copy-of select="."/>
                            </xsl:for-each>
                        </xsl:element>
                    </xsl:otherwise>
                </xsl:choose>
                <xsl:element name="Header">
                    <xsl:attribute name="RONum">
                        <xsl:value-of select="//Envelope/@RONum"/>
                    </xsl:attribute>
                    <xsl:attribute name="OwnerFName">
                        <xsl:value-of select="//Admin/@OwnerF"/>
                    </xsl:attribute>
                    <xsl:attribute name="OwnerLName">
                        <xsl:value-of select="//Admin/@OwnerL"/>
                    </xsl:attribute>
                    <xsl:attribute name="VIN">
                        <xsl:value-of select="//Vehicle/@TransVIN"/>
                    </xsl:attribute>
                    <xsl:attribute name="Mileage">
                        <xsl:value-of select="//Vehicle/@TransMileage"/>
                    </xsl:attribute>
                    <xsl:attribute name="Year">
                        <xsl:value-of select="//Vehicle/@TransYear"/>
                    </xsl:attribute>
                    <xsl:attribute name="Make">
                        <xsl:if test="//Vehicle/@ManufName[. != '']">
                            <xsl:choose>
                                <xsl:when test="//Vehicle/@ManufName[. = 'Geo']">CHEV</xsl:when>
                                <xsl:when test="//Vehicle/@ManufName[. = 'Chev-GMC Truck']">CHEV</xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="//Vehicle/@ManufName"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:if>
                        <xsl:if test="//Vehicle/@ManufName[. = '']">
                            <xsl:value-of select="//Vehicle/@ManufCode"/>
                        </xsl:if>
                    </xsl:attribute>
                    <xsl:attribute name="Model">
                        <xsl:value-of select="//Vehicle/@TransModel"/>
                    </xsl:attribute>
                    <xsl:attribute name="Description">
                        <xsl:value-of select="//Vehicle/@TransYear"/>
                        <xsl:text></xsl:text>
                        <xsl:value-of select="//Vehicle/@ManufName"/>
                        <xsl:text></xsl:text>
                        <xsl:value-of select="//Vehicle/@TransModel"/>
                    </xsl:attribute>
                    <xsl:attribute name="LastSupplLevel">
                        <xsl:choose>
                            <xsl:when test="//Envelope/@TransactionType = 'E'">0</xsl:when>
                            <xsl:when test="substring(//Envelope/@SupplementNum, 1, 1) = 'S'">
                                <xsl:value-of select="substring(//Envelope/@SupplementNum, 2)"/>
                            </xsl:when>
                            <xsl:otherwise>0</xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                </xsl:element>
                <xsl:apply-templates select="PartsList"/>
                <xsl:element name="Envelope">
                    <xsl:element name="Software">
                        <xsl:attribute name="Manifest">Audatex.xml</xsl:attribute>
                        <xsl:attribute name="Descriptor">Audatex.xsl</xsl:attribute>
                        <xsl:attribute name="System">
                            <xsl:value-of select="//Envelope/@EstimatingSystem"/>
                        </xsl:attribute>
                        <xsl:attribute name="Version">
                            <xsl:value-of select="//Envelope/@SoftwareVersion"/>
                        </xsl:attribute>
                        <xsl:attribute name="SystemName">
                            <xsl:value-of select="//Envelope/@SystemName"/>
                        </xsl:attribute>
                        <xsl:attribute name="EstimateFileID">
                            <xsl:value-of select="//Envelope/@EstimateFileID"/>
                        </xsl:attribute>
                        <xsl:attribute name="UniqueFileID">
                            <xsl:value-of select="//Envelope/@UniqueFileID"/>
                        </xsl:attribute>
                        <xsl:attribute name="EstimateID">
                            <xsl:value-of select="//Envelope/@EstimatingSystem"/>-<xsl:value-of
                                select="//Envelope/@SoftwareVersion"/>-
                            <xsl:value-of select="//Envelope/@UniqueFileID"/>
                        </xsl:attribute>
                        <xsl:attribute name="EstimateIDv2">
                            <xsl:value-of select="//Envelope/@EstimatingSystem"/>-
                            <xsl:value-of select="//Envelope/@UniqueFileID"/>
                        </xsl:attribute>
                        <xsl:attribute name="EstimateFormatVersion">
                            <xsl:value-of select="//Envelope/@EMSVersion"/>
                        </xsl:attribute>
                    </xsl:element>
                </xsl:element>
                <xsl:element name="Totals">
                    <xsl:attribute name="GrandTotalAmount">
                        <xsl:value-of select="//Total/@GrandTotalAmount"/>
                    </xsl:attribute>
                </xsl:element>
                <xsl:element name="Administrative">
                    <xsl:element name="Owner">
                        <xsl:attribute name="FName">
                            <xsl:value-of select="//Admin/@OwnerF"/>
                        </xsl:attribute>
                        <xsl:attribute name="LName">
                            <xsl:value-of select="//Admin/@OwnerL"/>
                        </xsl:attribute>
                        <xsl:attribute name="Company">
                            <!--<xsl:value-of select="//Admin/@OwnerCompanyName"/>-->
                        </xsl:attribute>
                        <xsl:attribute name="Address">
                            <!--<xsl:value-of select="//Admin/@OwnerAddr1"/>-->
                        </xsl:attribute>
                        <xsl:attribute name="Address2">
                            <!--<xsl:value-of select="//Admin/@OwnerAddr2"/>-->
                        </xsl:attribute>
                        <xsl:attribute name="City">
                            <!--<xsl:value-of select="//Admin/@OwnerCity"/>-->
                        </xsl:attribute>
                        <xsl:attribute name="State">
                            <xsl:value-of select="//Admin/@OwnerState"/>
                        </xsl:attribute>
                        <xsl:attribute name="Zip">
                            <!--<xsl:choose>
                                <xsl:when test="contains(//Admin/@OwnerZip, '-')">
                                    <xsl:choose>
                                        <xsl:when test="string-length(substring-before(//Admin/@OwnerZip, '-'))=5">
                                            <xsl:choose>
                                                <xsl:when test="string-length(substring-after(//Admin/@OwnerZip, '-'))=4">
                                                    <xsl:value-of select="//Admin/@OwnerZip"/>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <xsl:value-of select="substring(//Admin/@OwnerZip, 1, 5)"/>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                        </xsl:when>
                                    </xsl:choose>
                                </xsl:when>
                                <xsl:when test="string-length(//Admin/@OwnerZip)=9">
                                    <xsl:value-of select="substring(//Admin/@OwnerZip, 1, 5)"/>-<xsl:value-of select="substring(//Admin/@OwnerZip, 6, 4)"/>
                                </xsl:when>
                                <xsl:when test="string-length(//Admin/@OwnerZip)&gt;4">
                                    <xsl:value-of select="substring(//Admin/@OwnerZip, 1, 5)"/>
                                </xsl:when>
                            </xsl:choose>-->
                        </xsl:attribute>
                        <xsl:attribute name="Country">
                            <!--<xsl:value-of select="//Admin/@OwnerCountry"/>-->
                        </xsl:attribute>
                        <xsl:attribute name="Phone">
                            <!--<xsl:choose>
                                <xsl:when test="//Admin/@OwnerPhone1Ext[. != '']">
                                    <xsl:value-of select="//Admin/@OwnerPhone1"/>&#32;x<xsl:value-of select="//Admin/@OwnerPhone1Ext"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="//Admin/@OwnerPhone1"/>
                                </xsl:otherwise>
                            </xsl:choose>-->
                        </xsl:attribute>
                        <xsl:attribute name="Phone2">
                            <!--<xsl:choose>
                                <xsl:when test="//Admin/@OwnerPhone2Ext[. != '']">
                                    <xsl:value-of select="//Admin/@OwnerPhone2"/>&#32;x<xsl:value-of select="//Admin/@OwnerPhone2Ext"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="//Admin/@OwnerPhone2"/>
                                </xsl:otherwise>
                            </xsl:choose>-->
                        </xsl:attribute>
                        <xsl:attribute name="Fax">
                            <!--<xsl:choose>
                                <xsl:when test="//Admin/@OwnerFaxExt[. != '']">
                                    <xsl:value-of select="//Admin/@OwnerFax"/>&#32;x<xsl:value-of select="//Admin/@OwnerFaxExt"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="//Admin/@OwnerFax"/>
                                </xsl:otherwise>
                            </xsl:choose>-->
                        </xsl:attribute>
                        <xsl:attribute name="Email">
                            <!--<xsl:value-of select="//Admin/@OwnerEmail"/>-->
                        </xsl:attribute>
                    </xsl:element>
                    <xsl:element name="InsuranceCompany">
                        <xsl:attribute name="Id">
                            <xsl:value-of select="//Admin/@InsuranceCompanyID"/>
                        </xsl:attribute>
                        <xsl:attribute name="Name">
                            <xsl:value-of select="//Admin/@InsuranceCompanyName"/>
                        </xsl:attribute>
                        <xsl:attribute name="Address">
                            <xsl:value-of select="//Admin/@InsuranceAddr1"/>
                        </xsl:attribute>
                        <xsl:attribute name="Address2">
                            <xsl:value-of select="//Admin/@InsuranceAddr2"/>
                        </xsl:attribute>
                        <xsl:attribute name="City">
                            <xsl:value-of select="//Admin/@InsuranceCity"/>
                        </xsl:attribute>
                        <xsl:attribute name="State">
                            <xsl:value-of select="//Admin/@InsuranceState"/>
                        </xsl:attribute>
                        <xsl:attribute name="Zip">
                            <xsl:choose>
                                <xsl:when test="contains(//Admin/@InsuranceZip, '-')">
                                    <xsl:choose>
                                        <xsl:when test="string-length(substring-before(//Admin/@InsuranceZip, '-'))=5">
                                            <xsl:choose>
                                                <xsl:when
                                                        test="string-length(substring-after(//Admin/@InsuranceZip, '-'))=4">
                                                    <xsl:value-of select="//Admin/@InsuranceZip"/>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <xsl:value-of select="substring(//Admin/@InsuranceZip, 1, 5)"/>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                        </xsl:when>
                                    </xsl:choose>
                                </xsl:when>
                                <xsl:when test="string-length(//Admin/@InsuranceZip)=9">
                                    <xsl:value-of select="substring(//Admin/@InsuranceZip, 1, 5)"/>-
                                    <xsl:value-of select="substring(//Admin/@InsuranceZip, 6, 4)"/>
                                </xsl:when>
                                <xsl:when test="string-length(//Admin/@InsuranceZip)&gt;4">
                                    <xsl:value-of select="substring(//Admin/@InsuranceZip, 1, 5)"/>
                                </xsl:when>
                            </xsl:choose>
                        </xsl:attribute>
                        <xsl:attribute name="Country">
                            <xsl:value-of select="//Admin/@InsuranceCountry"/>
                        </xsl:attribute>
                        <xsl:attribute name="Phone">
                            <xsl:choose>
                                <xsl:when test="//Admin/@InsurancePhone1Ext[. != '']">
                                    <xsl:value-of select="//Admin/@InsurancePhone1"/>&#32;x
                                    <xsl:value-of select="//Admin/@InsurancePhone1Ext"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="//Admin/@InsurancePhone1"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                        <xsl:attribute name="Phone2">
                            <xsl:choose>
                                <xsl:when test="//Admin/@InsurancePhone2Ext[. != '']">
                                    <xsl:value-of select="//Admin/@InsurancePhone2"/>&#32;x
                                    <xsl:value-of select="//Admin/@InsurancePhone2Ext"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="//Admin/@InsurancePhone2"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                        <xsl:attribute name="Fax">
                            <xsl:choose>
                                <xsl:when test="//Admin/@InsuranceFaxExt[. != '']">
                                    <xsl:value-of select="//Admin/@InsuranceFax"/>&#32;x
                                    <xsl:value-of select="//Admin/@InsuranceFaxExt"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="//Admin/@InsuranceFax"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                        <xsl:attribute name="Email">
                            <xsl:value-of select="//Admin/@InsuranceEmail"/>
                        </xsl:attribute>
                    </xsl:element>
                    <xsl:element name="Insured">
                        <xsl:attribute name="LastName">
                            <xsl:value-of select="//Admin/@InsuranceLName"/>
                        </xsl:attribute>
                    </xsl:element>
                    <xsl:element name="Claim">
                        <xsl:attribute name="Number">
                            <xsl:value-of select="//Admin/@ClaimNumber"/>
                        </xsl:attribute>
                    </xsl:element>
                    <xsl:element name="Estimator">
                        <xsl:attribute name="FName">
                            <xsl:value-of select="//Admin2/@EstimatorF"/>
                        </xsl:attribute>
                        <xsl:attribute name="LName">
                            <xsl:value-of select="//Admin2/@EstimatorL"/>
                        </xsl:attribute>
                        <xsl:attribute name="Company">
                            <xsl:value-of select="//Admin2/@EstimatorCompanyName"/>
                        </xsl:attribute>
                        <xsl:attribute name="BodyShopCity">
                            <xsl:value-of select="//Admin2/@BodyShopCity"/>
                        </xsl:attribute>
                        <xsl:attribute name="BodyShopName">
                            <xsl:value-of select="//Admin2/@BodyShopName"/>
                        </xsl:attribute>
                        <xsl:attribute name="Address">
                            <xsl:value-of select="//Admin2/@EstimatorAddr1"/>
                        </xsl:attribute>
                        <xsl:attribute name="Address2">
                            <xsl:value-of select="//Admin2/@EstimatorAddr2"/>
                        </xsl:attribute>
                        <xsl:attribute name="City">
                            <xsl:value-of select="//Admin2/@EstimatorCity"/>
                        </xsl:attribute>
                        <xsl:attribute name="State">
                            <xsl:value-of select="//Admin2/@EstimatorState"/>
                        </xsl:attribute>
                        <xsl:attribute name="Zip">
                            <xsl:choose>
                                <xsl:when test="contains(//Admin2/@EstimatorZip, '-')">
                                    <xsl:choose>
                                        <xsl:when test="string-length(substring-before(//Admin2/@EstimatorZip, '-'))=5">
                                            <xsl:choose>
                                                <xsl:when
                                                        test="string-length(substring-after(//Admin2/@EstimatorZip, '-'))=4">
                                                    <xsl:value-of select="//Admin2/@EstimatorZip"/>
                                                </xsl:when>
                                                <xsl:otherwise>
                                                    <xsl:value-of select="substring(//Admin2/@EstimatorZip, 1, 5)"/>
                                                </xsl:otherwise>
                                            </xsl:choose>
                                        </xsl:when>
                                    </xsl:choose>
                                </xsl:when>
                                <xsl:when test="string-length(//Admin2/@EstimatorZip)=9">
                                    <xsl:value-of select="substring(//Admin2/@EstimatorZip, 1, 5)"/>-
                                    <xsl:value-of select="substring(//Admin2/@EstimatorZip, 6, 4)"/>
                                </xsl:when>
                                <xsl:when test="string-length(//Admin2/@EstimatorZip)&gt;4">
                                    <xsl:value-of select="substring(//Admin2/@EstimatorZip, 1, 5)"/>
                                </xsl:when>
                            </xsl:choose>
                        </xsl:attribute>
                        <xsl:attribute name="Country">
                            <xsl:value-of select="//Admin2/@EstimatorCountry"/>
                        </xsl:attribute>
                        <xsl:attribute name="Phone">
                            <xsl:choose>
                                <xsl:when test="//Admin2/@EstimatorPhone1Ext[. != '']">
                                    <xsl:value-of select="//Admin2/@EstimatorPhone1"/>&#32;x
                                    <xsl:value-of select="//Admin2/@EstimatorPhone1Ext"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="//Admin2/@EstimatorPhone1"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                        <xsl:attribute name="Phone2">
                            <xsl:choose>
                                <xsl:when test="//Admin2/@EstimatorPhone2Ext[. != '']">
                                    <xsl:value-of select="//Admin2/@EstimatorPhone2"/>&#32;x
                                    <xsl:value-of select="//Admin2/@EstimatorPhone2Ext"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="//Admin2/@EstimatorPhone2"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                        <xsl:attribute name="Fax">
                            <xsl:choose>
                                <xsl:when test="//Admin2/@EstimatorFaxExt[. != '']">
                                    <xsl:value-of select="//Admin2/@EstimatorFax"/>&#32;x
                                    <xsl:value-of select="//Admin2/@EstimatorFaxExt"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:value-of select="//Admin2/@EstimatorFax"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:attribute>
                        <xsl:attribute name="Email">
                            <xsl:value-of select="//Admin2/@EstimatorEmail"/>
                        </xsl:attribute>
                    </xsl:element>
                    <xsl:element name="RepairInformation">
                        <xsl:attribute name="VehicleDateIn">
                            <xsl:if test="string-length(//Admin2/@VehicleInDate)&gt;6">
                                <xsl:value-of select="substring-before(//Admin2/@VehicleInDate, ' ')"/>
                                <xsl:if test="string-length(//Admin2/@VehicleInTime)=4">
                                    &#32;<xsl:value-of select="substring(//Admin2/@VehicleInTime, 1, 2)"/>:
                                    <xsl:value-of select="substring(//Admin2/@VehicleInTime, 3, 2)"/>
                                </xsl:if>
                            </xsl:if>
                        </xsl:attribute>
                        <xsl:attribute name="EstimatedVehicleDateOut">
                            <xsl:if test="string-length(//Admin2/@TargetVehicleOutDate)&gt;6">
                                <xsl:value-of select="substring-before(//Admin2/@TargetVehicleOutDate,' ')"/>
                                <xsl:if test="string-length(//Admin2/@TargetVehicleOutTime)=4">
                                    &#32;<xsl:value-of select="substring(//Admin2/@TargetVehicleOutTime, 1, 2)"/>:
                                    <xsl:value-of select="substring(//Admin2/@TargetVehicleOutTime, 3, 2)"/>
                                </xsl:if>
                            </xsl:if>
                        </xsl:attribute>
                        <xsl:attribute name="VehicleDateOut">
                            <xsl:if test="string-length(//Admin2/@VehicleOutDate)&gt;6">
                                <xsl:value-of select="substring-before(//Admin2/@VehicleOutDate, ' ')"/>
                                <xsl:if test="string-length(//Admin2/@VehicleOutTime)=4">
                                    &#32;<xsl:value-of select="substring(//Admin2/@VehicleOutTime, 1, 2)"/>:
                                    <xsl:value-of select="substring(//Admin2/@VehicleOutTime, 3, 2)"/>
                                </xsl:if>
                            </xsl:if>
                        </xsl:attribute>
                    </xsl:element>
                </xsl:element>
            </xsl:element>
        </xsl:for-each>
    </xsl:template>
    <xsl:template match="PartsList">
        <xsl:element name="PartsList">
            <xsl:for-each select="Part">
                <xsl:element name="Part">
                    <!-- Part number translation rules -->
                    <xsl:variable name="OEMPartNumber">
                        <xsl:if test="substring(@TDPartNum, string-length(@TDPartNum) - 7) != ' GM PART'">
                            <xsl:value-of select="@TDPartNum"/>
                        </xsl:if>
                        <xsl:if test="substring(@TDPartNum, string-length(@TDPartNum) - 7) = ' GM PART'">
                            <xsl:value-of select="substring-before(@TDPartNum,' GM PART')"/>
                        </xsl:if>
                    </xsl:variable>
                    <xsl:variable name="AltPartNumber">
                        <xsl:value-of select="@AltPartNum"/>
                    </xsl:variable>
                    <xsl:variable name="PrimaryPartType">
                        <xsl:value-of select="@PartType"/>
                    </xsl:variable>
                    <xsl:variable name="PrimaryPartNumber">
                        <xsl:choose>
                            <xsl:when test="@PartType='PAN' or @PartType='PAG'">
                                <xsl:value-of select="$OEMPartNumber"/>
                            </xsl:when>
                            <xsl:when test="@PartType!='PAN' and @PartType!='PAG'">
                                <xsl:choose>
                                    <xsl:when test="$AltPartNumber!=''">
                                        <xsl:value-of select="$AltPartNumber"/>
                                    </xsl:when>
                                    <xsl:when test="$OEMPartNumber!=''">
                                        <xsl:value-of select="$OEMPartNumber"/>
                                    </xsl:when>
                                    <xsl:otherwise>Salvage or Assembly</xsl:otherwise>
                                </xsl:choose>
                            </xsl:when>
                        </xsl:choose>
                    </xsl:variable>
                    <xsl:variable name="SecondaryPartNumber">
                        <xsl:choose>
                            <xsl:when test="@PartType!='PAN'">
                                <xsl:value-of select="$OEMPartNumber"/>
                            </xsl:when>
                        </xsl:choose>
                    </xsl:variable>
                    <xsl:variable name="SecondaryPartType">
                        <xsl:choose>
                            <xsl:when test="@PartType='PAA'">PAN</xsl:when>
                        </xsl:choose>
                    </xsl:variable>
                    <xsl:attribute name="TDPartNum">
                        <xsl:value-of select="$PrimaryPartNumber"/>
                    </xsl:attribute>
                    <xsl:attribute name="AltPartNum">
                        <xsl:value-of select="$SecondaryPartNumber"/>
                    </xsl:attribute>
                    <xsl:attribute name="ExternalPartType">
                        <xsl:value-of select="$PrimaryPartType"/>
                    </xsl:attribute>
                    <xsl:attribute name="ExternalAltPartType">
                        <xsl:value-of select="$SecondaryPartType"/>
                    </xsl:attribute>
                    <xsl:attribute name="TDPartType">
                        <xsl:choose>
                            <xsl:when test="$PrimaryPartType='PAN' or $PrimaryPartType='PAP'">1</xsl:when>
                            <xsl:when test="$PrimaryPartType='PAA' or $PrimaryPartType='PATR'">2</xsl:when>
                            <xsl:when test="$PrimaryPartType='PAL'">3</xsl:when>
                            <xsl:when test="$PrimaryPartType='PAM' or $PrimaryPartType='PAC' or $PrimaryPartType='PAR'">
                                4
                            </xsl:when>
                            <xsl:otherwise>0</xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    <xsl:attribute name="AltPartType">
                        <xsl:choose>
                            <xsl:when test="$SecondaryPartType='PAN'">1</xsl:when>
                            <xsl:when test="$SecondaryPartType='PAA' or $SecondaryPartType='PATR'">2</xsl:when>
                            <xsl:when test="$SecondaryPartType='PAL'">3</xsl:when>
                            <xsl:when
                                    test="$SecondaryPartType='PAM' or $SecondaryPartType='PAC' or $SecondaryPartType='PAR'">
                                4
                            </xsl:when>
                            <xsl:otherwise>0</xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    <xsl:attribute name="TDPartDesc">
                        <xsl:value-of select="@TDPartDesc"/>
                    </xsl:attribute>
                    <xsl:attribute name="TDEstimate">
                        <xsl:choose>
                            <xsl:when test="@PartType='PAN'">
                                <xsl:value-of select="@TDEstimate"/>
                            </xsl:when>
                            <xsl:when test="@PartType='PAM'">
                                <xsl:value-of select="@ActPrice"/>
                            </xsl:when>
                            <xsl:when test="@PartType='PAA'">
                                <xsl:value-of select="@ActPrice"/>
                            </xsl:when>
                            <xsl:when test="@PartType='PAL'">
                                <xsl:value-of select="@ActPrice"/>
                            </xsl:when>
                            <xsl:otherwise>
                                <xsl:value-of select="@ActPrice"/>
                            </xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    <xsl:attribute name="TDPartQty">
                        <xsl:value-of select="@TDPartQty"/>
                    </xsl:attribute>
                    <xsl:attribute name="LineNumber">
                        <xsl:value-of select="@LineNumber"/>
                    </xsl:attribute>
                    <xsl:attribute name="SequenceNumber">
                        <xsl:value-of select="@SequenceNumber"/>
                    </xsl:attribute>
                    <xsl:attribute name="SupplLevel">
                        <xsl:choose>
                            <xsl:when test="@SupplementLevel = 'E'">0</xsl:when>
                            <xsl:when test="substring(@SupplementLevel, 1, 1) = 'S'">
                                <xsl:value-of select="substring(@SupplementLevel, 2)"/>
                            </xsl:when>
                            <xsl:otherwise>0</xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                    <xsl:attribute name="LaborType">
                        <xsl:value-of select="@LaborType"/>
                    </xsl:attribute>
                    <xsl:attribute name="LaborHours">
                        <xsl:value-of select="@LaborHours"/>
                    </xsl:attribute>
                    <xsl:attribute name="OperationCode">
                        <xsl:value-of select="@LaborOp"/>
                    </xsl:attribute>
                    <xsl:attribute name="PriceIncluded">
                        <xsl:value-of select="@PriceIncluded"/>
                    </xsl:attribute>
                    <xsl:attribute name="MarkUp">
                        <xsl:value-of select="@MarkUp"/>
                    </xsl:attribute>
                    <xsl:attribute name="CLPart">
                        <!-- CLPart is false if TRAN_CODE == 2 or TRAN_CODE == 3                           -->
                        <!-- CLPart is false if PartType is not 'PAN','PAP','PAL','PAG', 'PAM', or 'PAA', or 'PAC' or 'PATR'  -->
                        <!-- CLPart is false if LaborCode is only labor                                    -->
                        <!-- CLPart is false if OpCode is not "Remove/Replace" or "Remove/Replace Partial" -->
                        <!-- If LaborOp is OP1, then allow the part to import CP 12/28/08 for Shop Client Release 4.1.4 -->
                        <xsl:choose>
                            <xsl:when test="@TransactionCode='3'">False</xsl:when>
                            <xsl:when
                                    test="@TransactionCode='1' or @TransactionCode=' ' or @TransactionCode='' or @TransactionCode='2'">
                                <xsl:choose>
                                    <xsl:when
                                            test="@PartType='PAN' or @PartType='PAG' or @PartType='PAM' or @PartType='PAP' or @PartType='PAL' or @PartType='PAA' or @PartType='PAC' or @PartType='PATR'">
                                        <xsl:choose>
                                            <xsl:when
                                                    test="@LaborType='LAD' or @LaborType='LAE' or @LaborType='LAU' or @LaborType='LAT'">
                                                False
                                            </xsl:when>
                                            <xsl:otherwise>
                                                <xsl:choose>
                                                    <!--xsl:when test="@LaborOp='OP0'">False</xsl:when -->
                                                    <xsl:when test="@LaborOp='OP1'">False</xsl:when>
                                                    <xsl:when test="@LaborOp='OP2'">False</xsl:when>
                                                    <xsl:when test="@LaborOp='OP3'">False</xsl:when>
                                                    <xsl:when test="@LaborOp='OP4'">False</xsl:when>
                                                    <xsl:when test="@LaborOp='OP5'">False</xsl:when>
                                                    <xsl:when test="@LaborOp='OP6'">False</xsl:when>
                                                    <xsl:when test="@LaborOp='OP7'">False</xsl:when>
                                                    <xsl:when test="@LaborOp='OP8'">False</xsl:when>
                                                    <xsl:when test="@LaborOp='OP9'">False</xsl:when>
                                                    <xsl:when test="@LaborOp='OP10'">False</xsl:when>
                                                    <xsl:when test="@LaborOp='OP13'">False</xsl:when>
                                                    <xsl:when test="@LaborOp='OP14'">False</xsl:when>
                                                    <xsl:when test="@LaborOp='OP15'">False</xsl:when>
                                                    <xsl:when test="@LaborOp='OP16'">False</xsl:when>
                                                    <xsl:otherwise>True</xsl:otherwise>
                                                </xsl:choose>
                                            </xsl:otherwise>
                                        </xsl:choose>
                                    </xsl:when>
                                    <xsl:otherwise>False</xsl:otherwise>
                                </xsl:choose>
                            </xsl:when>
                            <xsl:otherwise>False</xsl:otherwise>
                        </xsl:choose>
                    </xsl:attribute>
                </xsl:element>
            </xsl:for-each>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>