<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp   "&#160;">
<!ENTITY copy   "&#169;">
]>
<!--

-->
<xsl:stylesheet version="3.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:ou="http://omniupdate.com/XSL/Variables"
    xmlns:fn="http://omniupdate.com/XSL/Functions"
    xmlns:ouc="http://omniupdate.com/XSL/Variables"
    xmlns="http://www.w3.org/1999/xhtml"
    exclude-result-prefixes="xsl xs ou fn ouc"
    expand-text="yes">

    <xsl:import href="_shared/template-matches.xsl" />
    <xsl:import href="_shared/force-self-closing.xsl" />
    <xsl:import href="_shared/variables.xsl" />
    <xsl:import href="_shared/functions.xsl" />
    <xsl:import href="_shared/breadcrumb.xsl" />
    <xsl:import href="_shared/snippets.xsl" />
    <xsl:import href="_shared/navigation.xsl" />
    <xsl:import href="_shared/galleries.xsl" />
    <xsl:import href="_shared/forms.xsl" />
    <xsl:import href="_shared/components.xsl" />

<!--  <xsl:output method="xhtml" version="1.0"
        doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
        doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"
        indent="yes" encoding="UTF-8" include-content-type="yes" omit-xml-declaration="yes" /> -->
    <xsl:output method="html" version="5.0" indent="yes" encoding="utf-8" include-content-type="no"/>
<!--  <xsl:output method="html" encoding="utf-8" doctype-public="-//W3C//DTD HTML 4.0 Transitional//EN" doctype-system="_http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/> -->

    <xsl:template name="page-directive" >

        <xsl:if test="$ou:action = 'pub' or $ou:action = 'cmp'">
            <xsl:copy-of select="ou:include-file('/_resources/includes/page-directive.inc')" />
        </xsl:if>

    </xsl:template>

    <xsl:template match="/document">
        <xsl:call-template name="page-directive" />

        <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
        <!-- <html xml:lang="en" lang="en"> -->
            <head id="ctl00_Head1">
                <xsl:copy-of select="ou:include-file('/_resources/includes/analytics/top-headcode-analytics.inc')" />
                <xsl:call-template name="common-headcode" />
                <xsl:call-template name="template-headcode" />
                <xsl:apply-templates select="headcode/node()" />
                <title><xsl:value-of select="$page-title" /></title>
                <xsl:call-template name="form-headcode" />

                <!-- Non-description meta with non-empty content -->
                <xsl:apply-templates
                    select="/document/ouc:properties[@label='metadata']/meta[
                        string-length(normalize-space(@content)) > 0
                        and translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') != 'description'
                    ]" />

                <!-- Our description meta (page or fallback) -->
                <xsl:call-template name="meta-description" />

            </head>
            <body>
                <xsl:copy-of select="ou:include-file('/_resources/includes/analytics/top-bodycode-analytics.inc')" />
                <xsl:apply-templates select="bodycode/node()" />
<!--              <div id="skip"><a href="#content">Skip to Main Content</a></div> -->
<!--              <div id="container" > -->
<!--                    <xsl:call-template name="common-header" />  -->
                    <xsl:call-template name="common-layout" /> 
<!--              </div> -->
                <xsl:call-template name="template-footcode" />
                <xsl:call-template name="form-footcode" />
                <xsl:apply-templates select="footcode/node()" /> 
                
            </body>
        </html>
    </xsl:template>

    <xsl:template name="common-layout">
        <div class="containerFooterWrapper">
            <div class="coverImage"></div>
            <xsl:if test="$contains-slideshow">
                <xsl:call-template name="header-gallery" />
            </xsl:if>
            <div id="container_layout">
                <div id="bkg_img_3col_layout">
                    <xsl:call-template name="page-content" />
                </div><div class="clear"></div>
            </div><div class="clear"></div>
            <xsl:call-template name="common-footer" />
        </div>
    </xsl:template>

    <xsl:template name="common-headcode">
        
        <xsl:variable name="social-media-graphic" select="social-media/ouc:div[@label='graphic']" />
        
        <xsl:copy-of select="ou:include-file('/_resources/includes/headcode.inc')" />
        <xsl:if test="$contains-slideshow">
            <script type="text/javascript" src="/_resources/js/CMSSlideShow.js"></script>
        </xsl:if>
        <script type="text/javascript">
            var OUC = OUC || {{}}; 
            OUC.pageName = OUC.pageName || "{$ou:path}";
            OUC.dirName = OUC.dirName || "{$dirname}";
            var page_id="<xsl:value-of select="concat(string-join(remove(tokenize(substring($ou:httproot, 1), '/'), count(tokenize(substring($ou:httproot, 1), '/'))), '/'),$ou:path)"/>";
        </script>
        
        <meta property="og:image" content="{$social-media-graphic}" />
        
    </xsl:template>

    <xsl:template name="common-header">
<!--        <xsl:copy-of select="ou:include-file('/_resources/includes/header.inc')" />-->
        <xsl:call-template name="unparsed-include-file">
            <xsl:with-param name="path">/_resources/includes/header.inc</xsl:with-param>
        </xsl:call-template>
    </xsl:template>

    <xsl:template name="common-footer">
<!--        <xsl:copy-of select="ou:include-file('/_resources/includes/footer.inc')" />-->
        <xsl:call-template name="unparsed-include-file">
            <xsl:with-param name="path">/_resources/includes/footer.inc</xsl:with-param>
        </xsl:call-template>
<!--      <xsl:copy-of select="ou:include-file('/_resources/includes/footcode.inc')" /> -->
        <xsl:copy-of select="ou:include-file('/_resources/includes/analytics/common.inc')" />
        <xsl:if test="$ou:analytics-include-path != ''">
            <xsl:copy-of select="ou:include-file($ou:analytics-include-path)" />
        </xsl:if>
        
        <xsl:if test="$ou:tracking-code != ''">
            <xsl:copy-of select="ou:include-file($ou:tracking-code)" />
        </xsl:if>
        
        <xsl:if test="$contains-slideshow">
            <xsl:comment> SLIDESHOW SCRIPT </xsl:comment>
            <script type="text/javascript">
                var ta,ia,ie,st,ss,ft,fs,xp,yp,ci,t,tar,tarl;
                var auto = true;
                var autodelay = 6;// time delay between each image
                ia = document.getElementById('slideshow_3col');
                CMSSlideShow();
            </script>
        </xsl:if>
        <xsl:if test="$contains-pretty-photo">
            <xsl:copy-of select="ou:include-file('/_resources/includes/pretty-photo.inc')" />
        </xsl:if>
        <xsl:if test="$contains-flex-slider">
            <xsl:copy-of select="ou:include-file('/_resources/includes/flex-slider.inc')" />
        </xsl:if>
    </xsl:template>

    <xsl:template name="page-content" />
    <xsl:template name="template-headcode" />
    <xsl:template name="template-footcode" />

    <!-- section  -->
    <xsl:template name="section-image">
        <div id="{if ($display-header) then 'page_id' else 'page_id_nophoto'}">
            <a href="{$ou:section-image-link}">
                <img src="{$sidebar-image}" style="float:left; {if ($display-header) then 'padding-top:10px' else ''}" border="0"  width="185" height="255" alt="{$ou:section-image-text}" title="{$ou:section-image-text}" />
            </a>
        </div>
        <xsl:if test="not($display-header)">
            <div class="clear"></div>
        </xsl:if>
    </xsl:template>

    <xsl:template name="section-header">
        <xsl:if test="$display-props-header">
            <div id="header_layout">
                <xsl:call-template name="section-image" />
                <div id="slideshow_3col">
                    <xsl:if test="ou:multiedit-props-field('header-type') = 'image'">
                        <img src="{ou:multiedit-props-field('header-image')/@src}" border="0" width="740" height="255" alt="{ou:multiedit-props-field('header-image')/@alt}" title="{ou:multiedit-props-field('header-image')/@alt}" />
                    </xsl:if>
                </div>
            </div><div class="clear"></div>
        </xsl:if>
    </xsl:template>

    <!-- page -->

    <xsl:template name="header">
        <xsl:choose>
            <xsl:when test="ou:multiedit-field('header-type') = 'section'">
                <xsl:call-template name="section-header" />
            </xsl:when>
            <xsl:otherwise>
                <div id="header_layout">
                    <xsl:call-template name="section-image" />
                    <div id="slideshow_3col">
                        <xsl:if test="ou:multiedit-field('header-type') = 'image'">
                            <img src="{ou:multiedit-field('header-image')/@src}" border="0" width="740" height="255" alt="{ou:multiedit-field('header-image')/@alt}" title="{ou:multiedit-field('header-image')/@alt}" />
                        </xsl:if>
                    </div>
                </div><div class="clear"></div>
            </xsl:otherwise>
        </xsl:choose>

    </xsl:template>

    <xsl:template name="sidebar-content">
        <xsl:if test="ou:pcf-param('sidebar-row-1') = 'display'">
            <xsl:apply-templates select="ou:multiedit-props-field('sidebar-row-1')" />
        </xsl:if>
        <xsl:if test="ou:pcf-param('display-menu2') = 'display'">
            <div role="complementary" aria-label="Related Links" class="box-content box-btm"><p class="leftSideBoxHeader">Related Links</p>
            <xsl:apply-templates select="ou:multiedit-props-field('info-related-links')" />
            </div>
        </xsl:if>
        <xsl:if test="ou:pcf-param('display-menu3') = 'display'">
            <div role="complementary" aria-label="Contact Information" class="box-content box-btm"><p class="leftSideBoxHeader">Contact Information</p><address>
            <xsl:apply-templates select="ou:multiedit-props-field('info-contact')" />
            </address></div> 
        </xsl:if>
    </xsl:template>

    <!--
        META DESCRIPTION LOGIC
        - If the page has a Description meta with non-empty content, use it.
        - Otherwise, use a generic institutional fallback.
    -->
    <xsl:template name="meta-description">
        <!-- Page-level Description (from PCF metadata) -->
        <xsl:variable name="pageDescription"
            select="/document/ouc:properties[@label='metadata']/meta[
                translate(@name,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz') = 'description'
            ]/@content" />

        <!-- Fallback blurb (used when Description is blank) -->
        <xsl:variable name="fallbackBlurb"
            select="'Founded in 1886, Winthrop University is a public, coeducational, comprehensive university that teaches students to live, learn, and lead for a lifetime.'" />

        <xsl:choose>
            <!-- CASE 1: PCF has a real description -->
            <xsl:when test="string-length(normalize-space($pageDescription)) &gt; 0">
                <meta name="description">
                    <xsl:attribute name="content">
                        <xsl:value-of select="normalize-space($pageDescription)" />
                    </xsl:attribute>
                </meta>
            </xsl:when>

            <!-- CASE 2: No page-level description -> use generic institutional fallback -->
            <xsl:otherwise>
                <meta name="description">
                    <xsl:attribute name="content">
                        <xsl:value-of select="$fallbackBlurb" />
                    </xsl:attribute>
                </meta>
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>

</xsl:stylesheet>
