<?xml version="1.0" encoding="utf-8"?>
<!-- =====COPYRIGHT===== -->
<!-- Copyright 2003 - 2012 Mobile Productivity, Inc. -->
<!-- =====COPYRIGHT===== -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
  <xsl:output method="text" indent="yes"/>

  <xsl:template match="/Xml">

    Declare @TId int;
    Declare @AnimationTypeId int;
    declare @AnimationId int;
    declare @AnimationModelId int;
    declare @returnvalue int;
    SELECT @AnimationModelId=6;
    <xsl:for-each select="SubCategory">

      <!--
  <SubCategory name="Inspect Lighting">
    <Task ROPackageName="EDGE WCI Inspection 3.5" name="Inspect fog lights and headlight low and bright beam operation" position="Exterior">
      <PosX1>579</PosX1>
      <PosY1>308</PosY1>
      <PosX2>612</PosX2>
      <PosY2>408</PosY2>
    </Task>
  </SubCategory>
  -->
      <xsl:for-each select="Task">

        use MPIPackages;
        Select @TId=TaskID
        From Task
        WHERE Name='<xsl:value-of select="@name" />'
        AND PackageID in
        (SELECT PackageId from Package WHERE Package.Name='<xsl:choose>
          <xsl:when test="@ROPackageName">EDGE 160-Point Inspection</xsl:when>
          <xsl:otherwise>EDGE WCI Inspection 3.5</xsl:otherwise>
        </xsl:choose>');

        <!--
  1	Exterior
  2	Interior
  3	Miscellaneous 
  4	Under Car
  5	Under Hood
-->


        <xsl:choose xml:space="default">
          <xsl:when test="@position='Exterior'">select @AnimationTypeId=1</xsl:when>
          <xsl:when test="@position='Interior'">select @AnimationTypeId=2</xsl:when>
          <xsl:when test="@position='Miscellaneous'">select @AnimationTypeId=3</xsl:when>
          <xsl:when test="@position='Undercarriage'">select @AnimationTypeId=4</xsl:when>
          <xsl:when test="@position='Underhood'">select @AnimationTypeId=5</xsl:when>
          <xsl:otherwise>select @AnimationTypeId=3</xsl:otherwise>
        </xsl:choose>
        use InteractiveInspectionsData;


        select @AnimationId=AnimationViewId
        from AnimationView
        where AnimationModelId=@AnimationModelId and AnimationViewTypeId=@AnimationTypeId;
        if NOT EXISTS(
        select AnimationViewId
        from AnimationView
        where AnimationModelId=@AnimationModelId and AnimationViewTypeId=@AnimationTypeId
        )
        BEGIN
        INSERT INTO AnimationView(AnimationModelId,AnimationViewTypeId,CreatedAt,CreatedBy)
        VALUES(@AnimationModelId,@AnimationTypeId,SYSDATETIME(),CURRENTUSER);
        select @AnimationId=scopeidentity();

        END

        use InteractiveInspectionsCode;

        EXEC	@returnvalue = [dbo].[InsertTaskPinPoint]
        @TaskPinPointID = NULL,
        @TaskID = @TId,
        @AnimationViewID = @AnimationId,
        @PinLocationX1 = <xsl:value-of select="PosX1"></xsl:value-of>,
        @PinLocationY1 = <xsl:value-of select="PosY1"></xsl:value-of>,
        @PinLocationX2 = <xsl:value-of select="PosX2"></xsl:value-of>,
        @PinLocationY2 = <xsl:value-of select="PosY2"></xsl:value-of>


      </xsl:for-each>

    </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>
