...
Code Block |
---|
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0" xmlns:urwg="http://www.gridforum.org/2003/ur-wg" xmlns:SimpleDateFormat="http://xml.apache.org/xalan/java/java.text.SimpleDateFormat" xmlns:Date="http://xml.apache.org/xalan/java/java.util.Date"> <!-- Declaration of parameters --> <!-- if you want to use a Sakai value or a passed in parameter from the --> <!-- query string, you should state it here --> <!-- The id parameter from the query string --> <xsl:param name="id"/> <!-- The sakai.tool.placement.ia parameter from the query string --> <xsl:param name="sakai.tool.placement.id"/> <!-- a number we can switch on to display different content for each page --> <xsl:param name="pageNumber"/> <!-- if passed, the created variable will be a key to a single blog Entry --> <xsl:param name="created"/> <!-- Declare output method --> <xsl:output method="html"/> <!-- Main Template outputs our HTML page --> <xsl:template match="/"> <xsl:choose> <xsl:when test="$pageNumber=4"> Rss! </xsl:when> <xsl:otherwise> <html> <head> <title>My Blog</title> <link rel="stylesheet" type="text/css"> <!--<xsl:attribute name="href">blogStyle.css</xsl:attribute>--> <xsl:attribute name="href"> <xsl:value-of select="/ospiPresentation/presentationFiles/style/artifact/fileArtifact/uri"/> </xsl:attribute> </link> </head> <body> <div id="wrapper"> <div id="header"> <xsl:attribute name="style"> <xsl:text>background-image:url('</xsl:text> <xsl:value-of select="/ospiPresentation/presentationFiles/backgroundImage/artifact/fileArtifact/uri"/> <xsl:text>')</xsl:text> </xsl:attribute> <img> <xsl:attribute name="src"> <xsl:value-of select="/ospiPresentation/presentationFiles/myLogo/artifact/fileArtifact/uri"/> </xsl:attribute> <xsl:attribute name="alt">My Institutions Logo</xsl:attribute> <xsl:attribute name="style">float: right;</xsl:attribute> </img> <h1>My Blog</h1> </div> <!-- a little menu to navigate --> <div id="menu"> <ul> <li> <xsl:call-template name="menuLink"> <xsl:with-param name="pageNumber"/> <xsl:with-param name="text">Last 5</xsl:with-param> </xsl:call-template> </li> <li> <xsl:call-template name="menuLink"> <xsl:with-param name="pageNumber">1</xsl:with-param> <xsl:with-param name="text">About Me</xsl:with-param> </xsl:call-template> </li> <li> <xsl:call-template name="menuLink"> <xsl:with-param name="pageNumber">2</xsl:with-param> <xsl:with-param name="text">Entry Index</xsl:with-param> </xsl:call-template> </li> <li> <xsl:call-template name="menuLink"> <xsl:with-param name="pageNumber">4</xsl:with-param> <xsl:with-param name="text">RSS Feed</xsl:with-param> </xsl:call-template> </li> </ul> </div> <div id="contentWrapper"> <div id="entryNav"> <h3>Blog Posts</h3> <ul> <xsl:for-each select="/ospiPresentation/blogEntry/artifact"> <xsl:sort data-type="number" select="Date:getTime(SimpleDateFormat:parse(SimpleDateFormat:new('EEE MMM dd kk:mm:ss zzz yyyy'), ./metaData/repositoryNode/created))" order="descending"/> <li> <a> <xsl:attribute name="href"> <xsl:text disable-output-escaping="yes">viewPresentation.osp?sakai.tool.placement.id=</xsl:text> <xsl:value-of select="$sakai.tool.placement.id"/> <xsl:text disable-output-escaping="yes">&id=</xsl:text> <xsl:value-of select="$id"/> <xsl:text disable-output-escaping="yes">&pageNumber=3&created=</xsl:text> <xsl:value-of select="./metaData/repositoryNode/created"/> </xsl:attribute> <xsl:value-of select="./metaData/displayName"/> </a> </li> </xsl:for-each> </ul> </div> <!-- a switch to select content for this page based on the value of pageNumber --> <div id="content"> <xsl:choose> <xsl:when test="$pageNumber=1"> <!-- about me --> About me Page </xsl:when> <xsl:when test="$pageNumber=2"> <!-- display an index of all blog entries --> <h3>All Entries</h3> <ul id="datedEntryList"> <xsl:for-each select="/ospiPresentation/blogEntry/artifact"> <xsl:sort data-type="number" select="Date:getTime(SimpleDateFormat:parse(SimpleDateFormat:new('EEE MMM dd kk:mm:ss zzz yyyy'), ./metaData/repositoryNode/created))" order="descending"/> <li> <a> <xsl:attribute name="href"> <xsl:text disable-output-escaping="yes">viewPresentation.osp?sakai.tool.placement.id=</xsl:text> <xsl:value-of select="$sakai.tool.placement.id"/> <xsl:text disable-output-escaping="yes">&id=</xsl:text> <xsl:value-of select="$id"/> <xsl:text disable-output-escaping="yes">&pageNumber=3&created=</xsl:text> <xsl:value-of select="./metaData/repositoryNode/created"/> </xsl:attribute> <xsl:value-of select="./metaData/displayName"/> - <xsl:value-of select="./metaData/repositoryNode/created"/> </a> </li> </xsl:for-each> </ul> </xsl:when> <xsl:when test="$pageNumber=3"> <!-- individual entry displayed --> <xsl:for-each select="/ospiPresentation/blogEntry/artifact[metaData/repositoryNode/created=$created]"> <xsl:call-template name="entry"> <xsl:with-param name="title"> <xsl:value-of select="./metaData/displayName"/> </xsl:with-param> <xsl:with-param name="date"> <xsl:value-of select="./metaData/repositoryNode/created"/> </xsl:with-param> <xsl:with-param name="body"> <xsl:value-of select="./structuredData/blogEntry/entryBody"/> </xsl:with-param> </xsl:call-template> </xsl:for-each> </xsl:when> <xsl:otherwise> <!-- last 5 blog entries --> <xsl:for-each select="/ospiPresentation/blogEntry/artifact[position() > 0]"> <!-- sort by year, moth, day created dates formatted like: Tue Jan 09 09:59:52 EST 2007 --> <xsl:sort data-type="number" select="Date:getTime(SimpleDateFormat:parse(SimpleDateFormat:new('EEE MMM dd kk:mm:ss zzz yyyy'), ./metaData/repositoryNode/created))" order="descending"/> <xsl:call-template name="entry"> <xsl:with-param name="title"> <xsl:value-of select="./metaData/displayName"/> </xsl:with-param> <xsl:with-param name="date"> <xsl:value-of select="./metaData/repositoryNode/created"/> </xsl:with-param> <xsl:with-param name="body"> <xsl:value-of select="./structuredData/blogEntry/entryBody"/> </xsl:with-param> </xsl:call-template> </xsl:for-each> </xsl:otherwise> </xsl:choose> </div> <!-- content --> <div style="clear: both"/> </div> <!-- contentWrapper --> </div> <!-- end wrapper div --> </body> </html> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="entry"> <xsl:param name="title"/> <xsl:param name="date"/> <xsl:param name="body"/> <div class="entry"> <h3> <xsl:value-of select="$title"/> </h3> <div class="date"> <xsl:value-of select="$date"/> </div> <div class="entryBody"> <xsl:value-of select="$body" disable-output-escaping="yes"/> </div> </div> </xsl:template> <!-- a named template to menu display links correctly --> <xsl:template name="menuLink"> <xsl:param name="pageNumber"/> <xsl:param name="text"/> <a> <xsl:attribute name="href"> <xsl:text disable-output-escaping="yes">viewPresentation.osp?sakai.tool.placement.id=</xsl:text> <xsl:value-of select="$sakai.tool.placement.id"/> <xsl:text disable-output-escaping="yes">&id=</xsl:text> <xsl:value-of select="$id"/> <xsl:text disable-output-escaping="yes">&pageNumber=</xsl:text> <xsl:value-of select="$pageNumber"/> </xsl:attribute> <xsl:value-of select="$text"/> </a> </xsl:template> <!-- from O'Reilly XSLT Cookbook, 2nd Edition --> <!-- Recipe 4.4. Calculating Julian and Absolute Day Numbers from a Specified Date --> <xsl:template name="calculate-julian-day"> <xsl:param name="year"/> <xsl:param name="month"/> <xsl:param name="day"/> <xsl:variable name="a" select="floor((14 - $month) div 12)"/> <xsl:variable name="y" select="$year + 4800 - $a"/> <xsl:variable name="m" select="$month + 12 * $a - 3"/> <xsl:value-of select="$day + floor((153 * $m + 2) div 5) + $y * 365 + floor($y div 4) - floor($y div 100) + floor($y div 400) - 32045"/> </xsl:template> </xsl:stylesheet> |