<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet SYSTEM "http://commons.omniupdate.com/dtd/standard.dtd">
<!--
BREADCRUMBS for UAEX 2013 Implementation

Assumes that a section properties files is being used to extract section titles. 
If there aren't any props files, the xsl can be modified to check the page title of the index/default page of each section instead.

Example:
<xsl:call-template name="breadcrumb">
	<xsl:with-param name="path" select="$ou:dirname"/>								
</xsl:call-template>

Requires ou:findPrevDir, which is defined in functions xsl.

PARAMETERS, from vars.xsl, for reference.

	<xsl:param name="index-file" select="ou:testVariable($ou:index-file,'default')"/> 
	<xsl:param name="extension" select="ou:testVariable($ou:extension,'aspx')"/> 

last updated 7/1/2013
-->
<xsl:stylesheet version="2.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">
    	
<!-- if a subfolder has been defined in Access Settings -->
		
<xsl:template name="emp-breadcrumb">
<xsl:param name="path" select="$dirname" /> <!-- defined in the vars xsl as $ou:dirname with a trailing '/' -->
<xsl:param name="title" select="$breadcrumbTitle" /> <!-- defined in vars as the title of the current page -->		
	
	<nav class="breadcrumbs">
	<span class="hidden">You are here: </span>

	<ul class="g3">
			
		<!-- begin the recursive template for the crumbs (below) -->
		<xsl:call-template name="bc-folders">
			<xsl:with-param name="path" select="$dirname"/>
		</xsl:call-template>
	
		<!-- breadcrumb title for current page -->
		<li><xsl:value-of select="$title" /></li>
		
	</ul>
	</nav>
	
</xsl:template>

<xsl:template name="bc-folders">
<xsl:param name="path" />
	
	<!-- The following variables assume that the section breadcrumbs is in a file called '_props.pcf'. With some config the file may be substitued for breadcrumb.xml, index.pcf etc -->
	<xsl:variable name="this-props-path" select="concat($ou:root, $ou:site, $path, $props-file)"/>	<!-- props-file is defined in vars xsl -->
	<xsl:variable name="title">
		<xsl:choose>
			<!-- test if there is a props file before trying to read it -->
			<xsl:when test="doc-available($this-props-path)">
				<xsl:copy-of select="ou:propsparam('sectionTitle',$this-props-path)"/>
			</xsl:when>
			<xsl:otherwise><xsl:if test="$ou:action!='pub'">System Message: Props File Not Found</xsl:if></xsl:otherwise>
		</xsl:choose>
	</xsl:variable>
	
	
	<xsl:if test="$path != $breadcrumbStart">
		<!-- begin recursive function if the current path doesn't match the root -->
		<xsl:call-template name="bc-folders">
			<xsl:with-param name="path" select="ou:findPrevDir($path)"/>
		</xsl:call-template>
	</xsl:if>

	<xsl:choose>
		<!-- if the path matches the current directory, and the current page is an index file, then display without an anchor element -->
		<xsl:when test="$path = $dirname and contains($ou:filename,$index-file)">
		<!--<li><xsl:value-of select="$title"/></li>-->
		</xsl:when>
		<xsl:when test="$title = ''"/>
		<xsl:otherwise>
			<li><a href="{$path}"><xsl:value-of select="$title"/></a></li>
		</xsl:otherwise>
	</xsl:choose>
	
	
</xsl:template>

<xsl:function name="ou:findPrevDir"> <!-- outputs parent directory path with trailing '/': /path/to/parent/ -->
		<xsl:param name="path" />
		<xsl:variable name="tokenPath" select="tokenize(substring($path, 2), '/')[if(substring($path,string-length($path)) = '/') then position() != last() else position()]" />
		<xsl:variable name="newPath" select="concat('/', string-join(remove($tokenPath, count($tokenPath)), '/') ,'/')"/>
		<xsl:value-of select="if($newPath = '//') then '/' else $newPath" />
</xsl:function>

</xsl:stylesheet>
