Skip to content

Instantly share code, notes, and snippets.

@bauhouse
Created October 16, 2011 15:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bauhouse/1291048 to your computer and use it in GitHub Desktop.
Save bauhouse/1291048 to your computer and use it in GitHub Desktop.
Project Template
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
Description:
This is a date formatting utility. The named template "format-date" takes 2 parameters:
1. date - [required] takes an ISO date (2005-12-01)
2. format - [optional] takes a format string.
Format options:
Y - year in 4 digits e.g. 1981, 1992, 2008
y - year in 2 digits e.g. 81, 92, 08
M - month as a full word e.g. January, March, September
m - month in 3 letters e.g. Jan, Mar, Sep
N - month in digits without leading zero
n - month in digits with leading zero
D - day with suffix and no leading zero e.g. 1st, 23rd
d - day in digits with leading zero e.g. 01, 09, 12, 25
x - day in digits with no leading zero e.g. 1, 9, 12, 25
T - time in 24-hours e.g. 18:30
t - time in 12-hours e.g. 6:30pm
W - weekday as a full word e.g. Monday, Tuesday
w - weekday in 3 letters e.g. Mon, Tue, Wed
Examples:
M => January
d M => 21 September
m D, y => Sep 21st, 81
n-d-y => 09-21-81
d/n/y => 21/09/81
d/n/y t => 21/09/81 6:30pm
-->
<xsl:template name="format-date">
<xsl:param name="date"/>
<xsl:param name="format" select="'D M, Y'"/>
<xsl:choose>
<xsl:when test="string-length($format) &lt;= 13">
<xsl:call-template name="date-controller">
<xsl:with-param name="date" select="$date"/>
<xsl:with-param name="format" select="$format"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:text>Error: format parameter is not correctly set. You have: </xsl:text>
<xsl:value-of select="string-length($format)"/>
<xsl:text>.</xsl:text>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="date-controller">
<xsl:param name="date"/>
<xsl:param name="format"/>
<xsl:param name="letter" select="substring($format,1,1)"/>
<xsl:param name="tletter" select="translate($letter,'DMNYTW','dmnytw')"/>
<xsl:choose>
<xsl:when test="$tletter = 'y'">
<xsl:call-template name="format-year">
<xsl:with-param name="date" select="$date"/>
<xsl:with-param name="format" select="$letter"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$tletter = 'm'">
<xsl:call-template name="format-month">
<xsl:with-param name="date" select="$date"/>
<xsl:with-param name="format" select="$letter"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$tletter = 'n'">
<xsl:call-template name="format-month">
<xsl:with-param name="date" select="$date"/>
<xsl:with-param name="format" select="$letter"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$tletter = 'd'">
<xsl:call-template name="format-day">
<xsl:with-param name="date" select="$date"/>
<xsl:with-param name="format" select="$letter"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$tletter = 'x'">
<xsl:call-template name="format-day">
<xsl:with-param name="date" select="$date"/>
<xsl:with-param name="format" select="$letter"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$tletter = 't'">
<xsl:call-template name="format-time">
<xsl:with-param name="time" select="$date/@time"/>
<xsl:with-param name="format" select="$letter"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$tletter = 'w'">
<xsl:call-template name="format-weekday">
<xsl:with-param name="weekday" select="$date/@weekday"/>
<xsl:with-param name="format" select="$letter"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$letter"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="$letter = not('')">
<xsl:call-template name="date-controller">
<xsl:with-param name="date" select="$date"/>
<xsl:with-param name="format" select="substring($format,2)"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="format-year">
<xsl:param name="date"/>
<xsl:param name="year" select="substring($date,1,4)"/>
<xsl:param name="format" select="'y'"/>
<xsl:choose>
<xsl:when test="$format = 'y'">
<xsl:value-of select="substring($year,3)"/>
</xsl:when>
<xsl:when test="$format = 'Y'">
<xsl:value-of select="$year"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="format-month">
<xsl:param name="date"/>
<xsl:param name="month" select="format-number(substring($date,6,2), '##')"/>
<xsl:param name="format" select="'m'"/>
<xsl:param name="month-word">
<xsl:choose>
<xsl:when test="$month = 01">January</xsl:when>
<xsl:when test="$month = 02">February</xsl:when>
<xsl:when test="$month = 03">March</xsl:when>
<xsl:when test="$month = 04">April</xsl:when>
<xsl:when test="$month = 05">May</xsl:when>
<xsl:when test="$month = 06">June</xsl:when>
<xsl:when test="$month = 07">July</xsl:when>
<xsl:when test="$month = 08">August</xsl:when>
<xsl:when test="$month = 09">September</xsl:when>
<xsl:when test="$month = 10">October</xsl:when>
<xsl:when test="$month = 11">November</xsl:when>
<xsl:when test="$month = 12">December</xsl:when>
</xsl:choose>
</xsl:param>
<xsl:choose>
<xsl:when test="$format = 'm'">
<xsl:value-of select="substring($month-word, 1,3)"/>
</xsl:when>
<xsl:when test="$format = 'M'">
<xsl:value-of select="$month-word"/>
</xsl:when>
<xsl:when test="$format = 'n'">
<xsl:value-of select="format-number($month, '00')"/>
</xsl:when>
<xsl:when test="$format = 'N'">
<xsl:value-of select="format-number($month, '0')"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="format-day">
<xsl:param name="date"/>
<xsl:param name="day" select="format-number(substring($date,9,2),'00')"/>
<xsl:param name="format" select="'d'"/>
<xsl:param name="suffix">
<xsl:choose>
<xsl:when test="(substring($day,2) = 1) and not(substring($day,1,1) = 1)">st</xsl:when>
<xsl:when test="(substring($day,2) = 2) and not(substring($day,1,1) = 1)">nd</xsl:when>
<xsl:when test="(substring($day,2) = 3) and not(substring($day,1,1) = 1)">Rd</xsl:when>
<xsl:otherwise>th</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:choose>
<xsl:when test="$format = 'd'">
<xsl:value-of select="$day"/>
</xsl:when>
<xsl:when test="$format = 'x'">
<xsl:value-of select="format-number($day,'0')"/>
</xsl:when>
<xsl:when test="$format = 'D'">
<xsl:value-of select="format-number($day,'0')"/>
<sup><xsl:value-of select="$suffix"/></sup>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="format-time">
<xsl:param name="time"/>
<xsl:param name="hour" select="substring-before($time, ':')"/>
<xsl:param name="minute" select="substring-after($time, ':')"/>
<xsl:param name="format" select="'T'"/>
<xsl:choose>
<xsl:when test="$format = 'T'">
<xsl:value-of select="$time"/>
</xsl:when>
<xsl:when test="$format = 't'">
<xsl:choose>
<xsl:when test="$hour mod 12 = 0">12</xsl:when>
<xsl:otherwise><xsl:value-of select="($hour mod 12)"/></xsl:otherwise>
</xsl:choose>
<xsl:value-of select="concat(':',$minute)"/>
<xsl:choose>
<xsl:when test="$hour &lt; 12">am</xsl:when>
<xsl:otherwise>pm</xsl:otherwise>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name="format-weekday">
<xsl:param name="weekday"/>
<xsl:param name="format" select="'w'"/>
<xsl:param name="result">
<xsl:choose>
<xsl:when test="$weekday = 1">Monday</xsl:when>
<xsl:when test="$weekday = 2">Tuesday</xsl:when>
<xsl:when test="$weekday = 3">Wednesday</xsl:when>
<xsl:when test="$weekday = 4">Thursday</xsl:when>
<xsl:when test="$weekday = 5">Friday</xsl:when>
<xsl:when test="$weekday = 6">Saturday</xsl:when>
<xsl:when test="$weekday = 7">Sunday</xsl:when>
</xsl:choose>
</xsl:param>
<xsl:choose>
<xsl:when test="$format = 'W'">
<xsl:value-of select="$result"/>
</xsl:when>
<xsl:when test="$format = 'w'">
<xsl:value-of select="substring($result,1,3)"/>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="navigation">
<xsl:apply-templates select="page[not(types/type = 'hidden')]"/>
</xsl:template>
<xsl:template match="page">
<li>
<xsl:if test="@handle = $current-page or @handle = $root-page">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
<a href="{$root}/{@handle}/">
<xsl:value-of select="name"/>
</a>
</li>
</xsl:template>
<xsl:template match="page/page">
<li>
<xsl:choose>
<xsl:when test="$root-page = ''">
<a href="{$root}/{$current-page}/{@handle}/">
<xsl:value-of select="name"/>
</a>
</xsl:when>
<xsl:otherwise>
<xsl:if test="@handle = $current-page">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
<a href="{$root}/{$root-page}/{@handle}/">
<xsl:value-of select="name"/>
</a>
</xsl:otherwise>
</xsl:choose>
</li>
</xsl:template>
<xsl:template name="secondary-navigation">
<xsl:choose>
<xsl:when test="$root-page = ''">
<xsl:apply-templates select="data/navigation/page[@handle=$current-page]/page[not(types/type = 'hidden')]"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="data/navigation/page[@handle=$root-page]/page[not(types/type = 'hidden')]"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:import href="../utilities/navigation.xsl"/>
<xsl:include href="../utilities/date-time.xsl"/>
<xsl:output method="xml"
doctype-public="-//W3C//DTD XHTML 1.0 Strict//EN"
doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
omit-xml-declaration="yes"
encoding="UTF-8"
indent="yes" />
<xsl:variable name="is-logged-in" select="/data/events/login-info/@logged-in"/>
<xsl:variable name="name" select="/data/events/login-info/name"/>
<xsl:variable name="username" select="/data/events/login-info/username"/>
<xsl:variable name="user-type" select="/data/events/login-info/@user-type"/>
<xsl:variable name="user-id" select="/data/events/login-info/@id"/>
<xsl:variable name="logged-in" select="/data/events/member-login-info/@logged-in"/>
<xsl:variable name="member" select="/data/member-info/entry"/>
<xsl:variable name="member-username" select="/data/member-info/entry/username"/>
<xsl:variable name="permissions" select="/data/member-info/entry/role"/>
<xsl:variable name="current-uri-path" select="substring-before($current-url,'?')" />
<xsl:param name="access" select="'members'" />
<!-- Project Parameters -->
<xsl:param name="client-name" select="'Client Name'" />
<xsl:param name="project-title" select="'Project Title'" />
<xsl:template match="/">
<html lang="en">
<head>
<xsl:apply-templates mode="page-title" />
<meta name="description" content="Strategy, Design and Technology resources for the web agency, Domain7 Solutions Inc" />
<meta name="author" content="Domain7" />
<!-- Mobile viewport optimized: j.mp/bplateviewport -->
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<xsl:apply-templates mode="css" />
<!-- All JavaScript at the bottom, except for Modernizr which enables HTML5 elements & feature detects -->
<script src="{$workspace}/assets/project/js/lib/modernizr-1.6.min.js"></script>
</head>
<body id="{$current-page}-page">
<xsl:apply-templates select="data/params/readonly-mode[. = 'yes']" />
<!-- div class="user">
<xsl:call-template name="login-panel" />
</div -->
<div class="page">
<xsl:apply-templates mode="header" />
<xsl:apply-templates mode="nav" />
<xsl:apply-templates mode="aside" />
<xsl:apply-templates />
<xsl:apply-templates mode="footer" />
<xsl:apply-templates mode="js" />
</div>
</body>
</html>
</xsl:template>
<xsl:template match="data" mode="page-title">
<title>
<xsl:value-of select="$page-title" />
<xsl:text> | </xsl:text>
<xsl:value-of select="$project-title" />
<xsl:text> | </xsl:text>
<xsl:value-of select="$client-name" />
</title>
</xsl:template>
<xsl:template match="data" mode="css">
<link rel="stylesheet" href="{$workspace}/assets/project/css/main.css?v1.0" />
<link rel="stylesheet" href="{$workspace}/assets/project/css/process.css?v1.0" />
</xsl:template>
<xsl:template match="data" mode="js">
<script type="text/javascript" src="{$workspace}/assets/project/js/lib/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="{$workspace}/assets/project/js/system.js"></script>
</xsl:template>
<xsl:template match="data" mode="header">
<header class="masthead">
<h1 class="logo"><a href="{$root}/">Domain7</a></h1>
<!-- xsl:if test="$logged-in = 'yes' or $is-logged-in = 'true'" -->
<nav>
<ul class="menu menu-buttons">
<xsl:apply-templates select="member-navigation/page" />
</ul>
</nav>
<!-- /xsl:if -->
</header>
</xsl:template>
<xsl:template match="data" mode="nav" />
<xsl:template match="data" mode="aside" />
<xsl:template match="member-navigation/page">
<li id="nav-{@handle}">
<xsl:if test="@handle = $current-page or @handle = $root-page">
<xsl:attribute name="class">current</xsl:attribute>
</xsl:if>
<a href="{$root}/{@handle}/">
<xsl:value-of select="name" />
</a>
</li>
</xsl:template>
<xsl:template match="data" mode="footer">
<footer>
<h4><a href="http://www.domain7.com/">Domain7 Solutions Inc</a></h4>
</footer>
</xsl:template>
<xsl:template name="login-panel">
<xsl:choose>
<xsl:when test="/data/events/member-login-info/role = 'Inactive'">
<div class="user-nav">
<ul>
<li>Account is not active.</li>
<li><a class="button" href="{$root}/members/activate/">Activate</a></li>
<li> or </li>
<li><a class="button" href="{$current-uri-path}?openid-action=logout">Logout</a></li>
</ul>
</div>
</xsl:when>
<xsl:when test="/data/events/member-login-info/@logged-in = 'yes'">
<div class="user-nav">
<ul>
<li>Logged in as
<a href="{$root}/people/{/data/member-info/entry/name/@handle}/">
<xsl:value-of select="/data/member-info/entry/name"/>
</a>
</li>
<li>
<a href="{$root}/members/{$member-username}/">My Profile</a>
</li>
<li>
<a class="button" href="{$current-uri-path}?openid-action=logout">
<xsl:if test="$openid-email"><xsl:attribute name="href"><xsl:value-of select="$current-uri-path" />?openid-action=logout</xsl:attribute></xsl:if>
Logout</a>
</li>
</ul>
</div>
</xsl:when>
<xsl:when test="/data/events/member-login-info/@result = 'error'">
<div id="login-panel">
<form id="failed-login" action="{$current-url}" method="post">
<fieldset>
<p>Login Failed.
<input id="submit" type="submit" name="reset" value="Try Again" class="button"/>
<span class="reset">or <a class="button" href="{$root}/members/reset-pass/">Reset Password</a></span>
</p>
</fieldset>
</form>
</div>
</xsl:when>
<xsl:otherwise>
<div id="login-panel">
<form action="" method="get" id="openid-login">
<input type="hidden" name="action" value="verify" />
<fieldset>
<input class="openid-identifier" name="openid-identifier" type="hidden" value="domain7.com" />
<input class="openid-submit button" type="submit" value="Sign In" />
<p><strong>Sign in</strong> with <a href="http://docs.domain7.com/">Google Apps</a></p>
</fieldset>
</form>
<form id="member-login" action="{$current-url}" method="post">
<fieldset>
<ul>
<li><input name="fields[username]" title="username" type="text" value="username" class="clear-on-focus"/></li>
<li><input name="fields[password]" title="chipmonk" type="password" value="chipmonk" class="clear-on-focus"/></li>
<li><input name="redirect" type="hidden" value="{$root}/dashboard/"/><input id="submit" type="submit" name="member-action[login]" value="Log In" class="button"/></li>
</ul>
</fieldset>
</form>
</div>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="data/params/readonly-mode">
<div id="system-messages">
<ul>
<li class="pending"><strong>This site is in read-only mode.</strong> All forms have been disabled while the site is being maintained. Thanks for your patience.</li>
</ul>
</div>
</xsl:template>
</xsl:stylesheet>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment