﻿<?xml version="1.0" encoding="utf-8"?>
<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:import href="AddActionInTemplateDetail.xslt"/>
    
    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="/">
        <xsl:variable name="TemplateURL" select="AjaxRequest/TemplateURL"></xsl:variable>
        <xsl:variable name="TopicID" select="AjaxRequest/Params/TemplateDetailID"></xsl:variable>
        <xsl:variable name="TemplateID" select="AjaxRequest/Params/ItemID"></xsl:variable>
        <xsl:variable name="TemplateRoles" select="AjaxRequest/Roles/."></xsl:variable>     
        <xsl:variable name="ActionName" select="AjaxRequest/ActionDetail/Action/Item"></xsl:variable>
        <xsl:variable name="StartDate" select="AjaxRequest/ActionDetail/Action/StartDate"></xsl:variable>
        <xsl:variable name="DueDate" select="AjaxRequest/ActionDetail/Action/DueDate"></xsl:variable>
        <xsl:variable name="Role" select="AjaxRequest/ActionDetail/Action/Role"></xsl:variable>
        <xsl:variable name="Description" select="AjaxRequest/ActionDetail/Action/Description"></xsl:variable>
        <xsl:variable name="DaysPrior" select="AjaxRequest/ActionDetail/Action/DaysPrior"></xsl:variable>
        <xsl:variable name="TopicName" select="AjaxRequest/ActionDetail/Action/RelatedTo"></xsl:variable>
        <!--<xsl:variable name="BrandID" select="AjaxRequest/ActionDetail/Action/BrandID"/>-->

        <xsl:variable name="BrandID">
            <xsl:choose>
                <xsl:when test="AjaxRequest/ActionDetail/Action/BrandID">
                    <xsl:value-of select="AjaxRequest/ActionDetail/Action/BrandID"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:text>-99</xsl:text>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:variable>
               

        <xsl:call-template name="AddTemplateAction">
            <xsl:with-param name="TemplatePathURL" select="$TemplateURL"></xsl:with-param>
            <xsl:with-param name="TopicID" select="$TopicID"></xsl:with-param>
            <xsl:with-param name="TemplateID" select="$TemplateID"></xsl:with-param>            
            <xsl:with-param name="BrandID" select="$BrandID"></xsl:with-param>
            <xsl:with-param name="TemplateRoles" select="$TemplateRoles"></xsl:with-param>          
            <xsl:with-param name="ActionName" select="$ActionName"></xsl:with-param>
            <xsl:with-param name="StartDate" select="$StartDate"></xsl:with-param>
            <xsl:with-param name="DueDate" select="$DueDate"></xsl:with-param>
            <xsl:with-param name="Role" select="$Role"></xsl:with-param>
            <xsl:with-param name="Description" select="$Description"></xsl:with-param>
            <xsl:with-param name="DaysPrior" select="$DaysPrior"></xsl:with-param>
            <xsl:with-param name="TopicName" select="$TopicName"></xsl:with-param>
            <xsl:with-param name="Mode">
                <xsl:text>Update</xsl:text>
            </xsl:with-param>
        </xsl:call-template>
    </xsl:template>
</xsl:stylesheet>
