<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY amp   "&#38;">
<!ENTITY copy   "&#169;">
<!ENTITY gt   "&#62;">
<!ENTITY hellip "&#8230;">
<!ENTITY laquo  "&#171;">
<!ENTITY lsaquo   "&#8249;">
<!ENTITY lsquo   "&#8216;">
<!ENTITY lt   "&#60;">
<!ENTITY nbsp   "&#160;">
<!ENTITY quot   "&#34;">
<!ENTITY raquo  "&#187;">
<!ENTITY rsaquo   "&#8250;">
<!ENTITY rsquo   "&#8217;">
]>

<!--
Implementation Skeleton - 02/07/2020

Global Components XSL
This file contains templates and functions that control default behavior for standard OU Components
-->

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

	<!-- A template match for getting rid of the stray P element that wraps around a component when it is in Blue Pill Mode -->
	<xsl:template match="p[ouc:component][text()[normalize-space(.)] => empty()][count(element()) = 1]" mode="#all">
		<xsl:apply-templates select="element()" mode="#current"/>
	</xsl:template>

	<!-- Create a mode for working with OU standard component practices -->
	<xsl:mode name="ouc-component" on-no-match="shallow-copy"/>

	<!-- A match for ouc:component element in the unnamed namespace. This match changes the mode name to ouc-component. -->
	<xsl:template match="ouc:component">
		<xsl:apply-templates mode="ouc-component"/>
	</xsl:template>

	<!-- A match for the "data-ouc-test" attribute on elements inside an ouc component. This is for removing the attribute from the final output when elements pass the test. -->
	<xsl:template match="@data-ouc-test" mode="ouc-component"/>

	<!-- A match for elements inside ouc components that have empty "data-ouc-test" attributes. This is for removing elements that fail the test from the final output. -->
	<xsl:template match="element()[@data-ouc-test and normalize-space(@data-ouc-test) = '']" mode="ouc-component"/>

	<!-- A match for the "data-ouc-not" attribute on elements inside an ouc component. This is for removing the attribute from the final output when elements pass the not test. -->
	<xsl:template match="@data-ouc-not" mode="ouc-component"/>

	<!-- A match for elements inside ouc components that have non-empty "data-ouc-not" attributes. This is for removing elements that fail the not test from the final output. -->
	<xsl:template match="element()[normalize-space(@data-ouc-not) != '']" mode="ouc-component"/>

	<!-- A match for elements inside ouc components that have "data-ouc-justedit" attributes. This attribute is used to show elements only inside JustEdit, so we remove all elements that have this attribute. -->
	<xsl:template match="element()[@data-ouc-justedit]" mode="ouc-component"/>

	<!-- College Cards -->
	<xsl:template match="ouc:component[@name='ou-college-cards']">
		<xsl:param name="cards" select="./div[@data-name='college-cards']/cards"/>

		<div class="college-cards">
			<div class="container">
				<div class="row g-4">
					<xsl:for-each select="$cards/card">
						<xsl:variable name="link" select="ou:textual-content(a)"/>
						<xsl:variable name="heading" select="ou:textual-content(heading)"/>
						<xsl:variable name="bold" select="ou:textual-content(bold)"/>

						<div class="col-12 col-md-6 col-lg-4 d-flex">
							<div class="card college-card justify-content-center">
								<xsl:choose>
									<xsl:when test="$link != '' ">
										<a href="{$link}" class="title">
											<xsl:if test="$heading != ''">{$heading}</xsl:if>
											<xsl:if test="$heading != '' and $bold != '' "><br/></xsl:if>
											<xsl:if test="$bold != ''"><strong>{$bold}</strong></xsl:if>
											<span class="fa-solid fa-arrow-right"></span>
										</a>
									</xsl:when>
									<xsl:otherwise>
										<div class="title">
											<xsl:if test="$heading != ''">{$heading}</xsl:if>
											<xsl:if test="$heading != '' and $bold != '' "><br/></xsl:if>
											<xsl:if test="$bold != ''"><strong>{$bold}</strong></xsl:if>
										</div>
									</xsl:otherwise>
								</xsl:choose>
							</div>
						</div>
					</xsl:for-each>

				</div>
			</div>
		</div>

	</xsl:template>
	<!-- END College Cards -->

	<!-- 	News Events Block -->
	<xsl:template match="ouc:component[@name='ou-news-events-block']">
		<xsl:variable name="news-data" select="./div[@data-name='news-events-data']/news"/>
		<xsl:variable name="events-data" select="./div[@data-name='news-events-data']/events"/>
		
		<xsl:variable name="tags" select="$news-data/tags"/>

		<xsl:variable name="news-filters">
			<xsl:if test="$news-data/featured = 'Yes'">
				<xsl:text>[featured/text()='true']</xsl:text>
			</xsl:if>
			<xsl:if test="$tags != ''">
				<xsl:variable name="logical-operator" select="if($news-data/filtering = 'all') then ' and ' else ' or '" />
				<xsl:text>[</xsl:text>
				<xsl:for-each select="tokenize($tags, ',')">
					<xsl:choose>
						<xsl:when test="contains(., '''')">
							<xsl:value-of select="'tags/tag=&quot;' || .=>normalize-space()=>replace('&quot;', '') || '&quot;'" />
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="'tags/tag=''' || normalize-space(.) || ''''" />
						</xsl:otherwise>
					</xsl:choose>
					<xsl:if test="position() != last()">
						<xsl:value-of select="$logical-operator" />
					</xsl:if>
				</xsl:for-each>
				<xsl:text>]</xsl:text>
			</xsl:if>
		</xsl:variable>


		<xsl:variable name="categories" select="$events-data/categories"/>

		<xsl:variable name="event-filters">
			<xsl:if test="$events-data/featured = 'Yes'">
				<xsl:text>[featured/text()='true']</xsl:text>
			</xsl:if>
			<xsl:if test="ou:not-empty($events-data/calendar)">
				<xsl:text>[</xsl:text>
				<xsl:for-each select="tokenize($events-data/calendar, ',')">
					<xsl:choose>
						<xsl:when test="contains(., '''')">
							<xsl:value-of select="'calendar/text()=&quot;' || .=>normalize-space()=>replace('&quot;', '') || '&quot;'" />
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="'calendar/text()=''' || normalize-space(.) || ''''" />
						</xsl:otherwise>
					</xsl:choose>
					<xsl:if test="position() != last()"> or </xsl:if>
				</xsl:for-each>
				<xsl:text>]</xsl:text>
			</xsl:if>
			<xsl:if test="$categories!=''">
				<xsl:variable name="logical-operator" select="if($events-data/filtering = 'all') then ' and ' else ' or '" />

				<xsl:text>[</xsl:text>
				<xsl:for-each select="tokenize($categories, ',')">
					<xsl:choose>
						<xsl:when test="contains(., '''')">
							<xsl:value-of select="'tags/tag=&quot;' || .=>normalize-space()=>replace('&quot;', '') || '&quot;'" />
						</xsl:when>
						<xsl:otherwise>
							<xsl:value-of select="'tags/tag=''' || normalize-space(.) || ''''" />
						</xsl:otherwise>
					</xsl:choose>
					<xsl:if test="position() != last()">
						<xsl:value-of select="$logical-operator" />
					</xsl:if>
				</xsl:for-each>
				<xsl:text>]</xsl:text>
			</xsl:if>

		</xsl:variable>

		<div class="news-events-split">
			<div class="container">
				<div class="row">
					<div class="col-lg-6 py-5 p-lg-5">
						<!-- News Block -->
						<xsl:if test="ou:not-empty($news-data/heading)">
							<div class="col-12">
								<div class="news-events-header">
									<h3>{$news-data/heading}</h3>
								</div>
							</div>
						</xsl:if>

						<div class="row">
							<xsl:call-template name="dmc">
								<xsl:with-param name="options">
									<datasource>news</datasource>
									<xpath>items/item{$news-filters}</xpath>
									<type>news-block</type>
									<items_per_page>2</items_per_page>
									<sort>date(start) asc</sort>
									<querystring_control>true</querystring_control>
								</xsl:with-param>

								<xsl:with-param name="script-name">blogs</xsl:with-param>
								<xsl:with-param name="debug" select="true()" />
							</xsl:call-template>
						</div>

						<xsl:if test="ou:not-empty($news-data/href)">
							<div class="news-events-footer">
								<a href="{$news-data/href}">
									View All News
									<span class="fa-solid fa-arrow-right"></span>
								</a>
							</div>
						</xsl:if>
						<!-- News Block -->
					</div>

					<div class="col-lg-6 py-5 p-lg-5">
						<!-- Events Block -->
						<div class="events">
							<xsl:if test="ou:not-empty($events-data/heading)">
								<div class="col-12">
									<div class="news-events-header">
										<h3>{$events-data/heading}</h3>
									</div>
								</div>
							</xsl:if>
							<xsl:call-template name="dmc">
								<xsl:with-param name="options">
									<datasource>events</datasource>
									<xpath>items/item{$event-filters}</xpath>
									<type>events-block</type>
									<items_per_page>3</items_per_page>
									<sort>date(start) asc</sort>
									<querystring_control>true</querystring_control>
								</xsl:with-param>

								<xsl:with-param name="script-name">generic</xsl:with-param>
								<xsl:with-param name="debug" select="true()" />
							</xsl:call-template>

							<xsl:if test="ou:not-empty($events-data/href)">
								<div class="news-events-footer">
									<a href="{$events-data/href}">
										View All Events
										<span class="fa-solid fa-arrow-right"></span>
									</a>
								</div>
							</xsl:if>
						</div>
						<!-- Events Block -->
					</div>
				</div>
			</div>
		</div>
	</xsl:template>
	<!-- 	END News Events Block -->

</xsl:stylesheet>