﻿<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:include href="Item.xslt"/>
    <xsl:template match="/">
        <xsl:variable name="TemplatePathURL" select ="Goal/TemplateURL"></xsl:variable>
        <xsl:variable name="GoalID" select="normalize-space(Goal/ID)"></xsl:variable>
        <xsl:variable name="OrderBy" select="Goal/OrderBy"/>
        <xsl:variable name="HostName" select="Goal/HostName"/>
        <xsl:variable name="DisplayCompleted" select="normalize-space(Goal/UserSettings/Completed)"></xsl:variable>
        <xsl:variable name="DisplayFuture" select="normalize-space(Goal/UserSettings/Future)"></xsl:variable>
        <xsl:variable name="DisplayCurrent" select="normalize-space(Goal/UserSettings/Current)"></xsl:variable>
        <xsl:variable name="DisplayMyItems" select="normalize-space(Goal/UserSettings/MyItems)"></xsl:variable>
        <xsl:variable name="DisplayOthersItems" select="normalize-space(Goal/UserSettings/Others)"></xsl:variable>
        <xsl:for-each select ="Goal/DetailItems/DetailItem">
            <xsl:variable name ="DisplayStyle">
                <xsl:choose>
                    <xsl:when test ="($DisplayCompleted = 1 and normalize-space(StatusID) = 4 and $DisplayMyItems = 1 and normalize-space(MineOrOther) = 'Me') 
                                                                    or ($DisplayCompleted = 1 and normalize-space(StatusID) = 4 and $DisplayOthersItems = 1 and normalize-space(MineOrOther) != 'Me')
                                                                    or ($DisplayFuture = 1 and normalize-space(StatusID) != 4 and normalize-space(TotalDays)&gt; 7 and $DisplayMyItems = 1 and normalize-space(MineOrOther) = 'Me')
                                                                    or ($DisplayFuture = 1 and normalize-space(StatusID) != 4 and normalize-space(TotalDays)&gt; 7 and $DisplayOthersItems = 1 and normalize-space(MineOrOther) != 'Me')
                                                                    or ($DisplayCurrent = 1 and normalize-space(StatusID) != 4 and normalize-space(TotalDays)&lt;= 7 and $DisplayMyItems = 1 and normalize-space(MineOrOther) = 'Me')
                                                                    or ($DisplayCurrent = 1 and normalize-space(StatusID) != 4 and normalize-space(TotalDays)&lt;= 7 and $DisplayOthersItems = 1 and normalize-space(MineOrOther) != 'Me')">
                        display:block
                    </xsl:when>
                    <xsl:otherwise>
                        display:none
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <xsl:call-template name="Item">
                <xsl:with-param name="ItemDivPrefix">
                    <xsl:text>div</xsl:text>
                </xsl:with-param>
                <xsl:with-param name="ItemID" select="ItemID"></xsl:with-param>
                <xsl:with-param name="ItemName" select="Item"></xsl:with-param>
                <xsl:with-param name="TemplatePathURL" select="$TemplatePathURL"></xsl:with-param>
                <xsl:with-param name="ItemSubID" select="ItemSubID"></xsl:with-param>
                <xsl:with-param name="ItemSubTitle" select="ItemSubTitle"></xsl:with-param>
                <xsl:with-param name="StatusID" select="StatusID"></xsl:with-param>
                <xsl:with-param name="HostName" select="$HostName"></xsl:with-param>
                <xsl:with-param name="OrderBy" select="$OrderBy"></xsl:with-param>
                <xsl:with-param name="PermissionID" select="PermissionID"></xsl:with-param>
                <xsl:with-param name="TotalDays" select="TotalDays"></xsl:with-param>
                <xsl:with-param name="KeyParameter" select="KeyParameter"></xsl:with-param>
                <xsl:with-param name="ItemType" select="ItemType"></xsl:with-param>
                <xsl:with-param name="RefItemType" select="RefItemTypeID"></xsl:with-param>
                <xsl:with-param name="RefItemID" select="RefItemID"></xsl:with-param>
                <xsl:with-param name="GoalID" select="$GoalID"></xsl:with-param>
                <xsl:with-param name="DisplayStyle" select="$DisplayStyle"></xsl:with-param>
                <xsl:with-param name="MineOrOther" select="normalize-space(MineOrOther)"></xsl:with-param>
                <xsl:with-param name="FirstName" select="FirstName"></xsl:with-param>
            </xsl:call-template>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>
