<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE document SYSTEM "http://commons.omniupdate.com/dtd/standard.dtd"> 
<!-- 
AZ Index Page									
-->
<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"
exclude-result-prefixes="ou xsl xs fn ouc">
	
	<xsl:import href="common.xsl"/>
	
	<xsl:variable name="directory" select="concat('file:',$ou:root,$ou:site, $ou:dirname)"/>
	<xsl:variable name="directory-f" select="concat($ou:root,$ou:site, $dirname)"/>
	<xsl:variable name="files" select="doc($directory)"/>
	
	
	<xsl:variable name="archive">
		<!-- only select PCF files that are not the default page, the props file, or the archive page -->
		<xsl:for-each select="$files/list/file[contains(.,'.pcf') and not(contains(.,'default.pcf')) and not(contains(.,'_props.pcf')) and not(contains(.,'archive.pcf'))]">																	
			
			<xsl:variable name="root-url" select="concat($dirname,replace(.,'.pcf','.aspx'))"/>
			<xsl:variable name="full-url" select="concat($domain,$root-url)"/><br/>
			
			<!--<xsl:if test="unparsed-text-available($full-url)">--><!-- check if the file is valid and has been published -->						
			<file>	
				<!-- variables for each file -->		
				<xsl:variable name="staging-path" select="concat($directory-f,.)"/>	<!-- generate path to staging file -->
				
				<!-- if PCF file is available, get the title -->
				<xsl:variable name="title" select="if(doc-available($staging-path)) then(normalize-space(doc($staging-path)/document/ouc:properties/title/text())) else(replace(.,'.pcf',''))"/><!-- ***as of 1/7/14, there are about 700 "plant of the week" pages for one of these archives, so this line slows things down considerably*** -->
				
				<xsl:variable name="allowed-characters">ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789.</xsl:variable>
				<xsl:variable name="validated-title"><xsl:value-of select="ou:capital(replace(normalize-space($title), '[^A-Za-z0-9()'']', ' '))"/></xsl:variable>
				
				<!-- xml -->
				<index><xsl:choose>
					<xsl:when test="contains($allowed-characters, substring(normalize-space($validated-title),1,1))"><xsl:value-of select="upper-case(substring(normalize-space($validated-title),1,1))"/></xsl:when>
					<xsl:otherwise><xsl:value-of select="upper-case(substring(normalize-space($validated-title),2,1))"/></xsl:otherwise>
				</xsl:choose></index><!-- finally, output the character to index the file by -->
				<title><xsl:value-of select="$validated-title"/></title> <!-- page title from pcf -->
				<link><xsl:value-of select="$root-url"/></link> <!-- root-relative link -->
			</file>
			<!--</xsl:if>-->
			
		</xsl:for-each>
	</xsl:variable>
	
	<!-- the archive page should use root relative links, whereas other pages should use absolute links -->
	<!-- the archive page does not use SSI for the tabs, because the archive page generates the SSI for the tabs -->
	<xsl:variable name="this-path" select="if(contains($ou:filename,'.aspx')) then('') else(replace($ou:path,'.inc','.aspx'))"/>
	
	
	<xsl:variable name="tabs">
		
		<ul class="tabset graybar">
			<xsl:for-each-group select="$archive/file" group-by="index">
				<xsl:sort select="index"/>
				
				<li>
					<xsl:if test="contains($ou:filename,'.aspx') and position()=1"> <!-- if archive page and the first link -->
						<xsl:attribute name="class" select="'active'"/>
					</xsl:if>
					<a href="{concat($this-path,'#tab',index)}"><xsl:value-of select="index"/></a>
				</li>							
				
			</xsl:for-each-group>
		</ul>
	</xsl:variable>
	
	<xsl:template name="page-content">
		
		<xsl:comment> main </xsl:comment>
		<div id="main">
			
			<xsl:comment> container</xsl:comment>		
			<div class="container">
				
				<xsl:comment> breadcrumbs </xsl:comment>			
				<xsl:call-template name="breadcrumb">
					<xsl:with-param name="path" select="$ou:dirname"/>								
				</xsl:call-template>
				
				<!-- BEGIN LEFT COLUMN -->			
				<xsl:comment> two-columns </xsl:comment>								
				<div id="two-columns" class="g3">									
					
					<xsl:comment> sidebar </xsl:comment>			
					<aside id="sidebar">																						
						<xsl:comment> accordion-holder </xsl:comment>
						<nav class="accordion-holder">
							<h1><xsl:value-of select="$navigationTitle"/></h1>
							<xsl:comment> left navigation </xsl:comment>
							<xsl:call-template name="nav-builder">
								<xsl:with-param name="top-level" select="substring($navigationStart,1,string-length($navigationStart)-1)"/>
								<xsl:with-param name="path" select="$ou:dirname" />
								<xsl:with-param name="last_crumb" select="$ou:dirname" />
							</xsl:call-template>
						</nav>								
					</aside>
					
					<!-- END LEFT COLUMN -->
					
					<!-- MIDDLE CONTENT -->
					<xsl:comment> content </xsl:comment>
					<section id="content">				
						<div class="content-holder">	
							
							<xsl:variable name="archiveOptions" select="string-join(ou:pcfparam('archiveOptions'))"/>
							
							<xsl:if test="contains($archiveOptions,'title')">
								<h1><xsl:value-of select="if(doc-available($props-path)) then(ou:propsparam('sectionTitle',$props-path)) else($dirname)"/></h1>						
							</xsl:if>
							
							<xsl:variable name="disclaimer" select="ou:pcfparam('disclaimer')"/>
							
							<xsl:if test="contains($archiveOptions,'disclaimer')">
								<p style="font-style:italic">
									<xsl:copy-of select="$disclaimer"/>
								</p>		
							</xsl:if>
							
							<xsl:if test="$ou:action='edt'">
								<div class="omniupdate message success">
									<p><strong>A to Z Archive Notes</strong></p>
									<ul>
										<li><strong>Before content is added to the A to Z Archive, all the starter files in the directory should be published</strong></li>
										<li>At least one detail page needs to be published in order to create an archive listing</li>
										<li><strong>To add a new page to the listing, publish the new page and then publish the archive</strong></li>
										<li>Pages are sorted alphabetically by Page Title</li>
										<li>Only detail pages will show the links pointing back to the archive listing</li>
										<li>All page types in the current directory (except the default and archive page), will be displayed in the listing</li>
										<li>Pages in child folders of the current directory will not be displayed in the listing</li>
										<li>To remove a page from the listing, delete or move the page from the folder and then re-publish the archive</li>
										<li><strong>Previously published pages do not need to be republished when new pages are added or removed or the disclaimer is changed</strong></li>
										<li>Disclaimer text for the archvie can be edited in Page Properties. Text can be hidden or displayed on a per page basis</li>
									</ul>					
								</div>
							</xsl:if>
							
							<xsl:apply-templates select="content/middle/maincontent/node()" mode="copy"/>
							
							
							<xsl:copy-of select="$tabs"/>
							
							
							<div class="tab-content tab-no-border">
								<xsl:for-each-group select="$archive/file" group-by="index">
									<xsl:sort select="index"/>
									<div id="tab{index}">								
										<xsl:variable name="matched-files" select="current-group()"/>										
										<xsl:for-each select="$matched-files">
											<xsl:sort select="upper-case(title)"/>			
											<a href="{link}"><xsl:value-of select="title"/></a><br/> 		
										</xsl:for-each>					
									</div>
								</xsl:for-each-group>						
							</div>
							
							<xsl:apply-templates select="content/middle/bottomcontent/node()" mode="copy"/>
							
						</div>
					</section>	
					<!-- END MIDDLE CONTENT -->
				</div>
				
				<div class="cf"><!--clearfix--></div>
				
				
			</div><!-- end container -->
		</div><!-- end main -->
		
	</xsl:template>
	
	
	
	
</xsl:stylesheet>
