|
Custom Pager and Collection rendering
Edit xsl/sparql_to_html.xsl in Islandora module:
- sparql_to_html.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="http://www.w3.org/2001/sw/DataAccess/rf1/result" xmlns:php="http://php.net/xsl" version="1.0" exclude-result-prefixes="php">
<!-- Red and White XSLT -->
<xsl:variable name="BASEURL" select="$baseUrl"/>
<xsl:variable name="PATH" select="$path"/>
<xsl:variable name="thisPid" select="$collectionPid"/>
<xsl:variable name="size" select="20"/>
<xsl:variable name="page" select="$hitPage"/>
<xsl:variable name="start" select="((number($page) - 1) * number($size)) + 1"/>
<xsl:variable name="end" select="($start - 1) + number($size)"/>
<xsl:variable name="cellsPerRow" select="4"/>
<xsl:variable name="count" select="count(s:sparql/s:results/s:result)"/>
<xsl:variable name="totpage" select="floor(($count - 1) div $size) + 1"/>
<xsl:template match="/">
<xsl:if test="$count>0">
<xsl:call-template name="render_pager"/>
<!-- <table class="collview" cellpadding="3" cellspacing="3" width="90%"> -->
<table class="collview">
<xsl:apply-templates select="s:sparql/s:results"/>
</table>
<br clear="all"/>
<xsl:call-template name="render_pager"/>
</xsl:if>
</xsl:template>
<xsl:template match="s:sparql/s:results">
<xsl:for-each select="s:result[position() mod $cellsPerRow = 1 and position()>=$start and position() <=$end]">
<tr>
<xsl:apply-templates select=". | following-sibling::s:result[position() < $cellsPerRow]"/>
</tr>
</xsl:for-each>
</xsl:template>
<xsl:template name="pageNumbers">
<xsl:param name="pageIndex"/>
<xsl:variable name="distanceFromCurrent" select="$pageIndex - $page"/>
<xsl:variable name="endIndex" select="$pageIndex * $size"/>
<xsl:variable name="startIndex" select="$endIndex - $size + 1"/>
<!-- show a maximum of nine paged sets on either side of the current paged set; just like Google does it -->
<xsl:choose>
<xsl:when test="($distanceFromCurrent > -5 and $distanceFromCurrent < 5)">
<xsl:choose>
<xsl:when test="$pageIndex = $page">
<li class="pager-current">
<xsl:choose>
<xsl:when test="$pageIndex = $totpage">
<xsl:value-of select="concat($startIndex, '-', $count)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($startIndex, '-', $endIndex)"/>
</xsl:otherwise>
</xsl:choose>
</li>
</xsl:when>
<xsl:otherwise>
<li class="pager-item">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $thisPid, '/-/Collection/', $pageIndex)"/>
</xsl:attribute>
<xsl:choose>
<xsl:when test="$pageIndex = $totpage">
<xsl:value-of select="concat($startIndex, '-', $count)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat($startIndex, '-', $endIndex)"/>
</xsl:otherwise>
</xsl:choose>
</a>
</li>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="($distanceFromCurrent = -5)">
<li class="pager-previous"><a><xsl:attribute name="href"><xsl:value-of select="concat($BASEURL, '/fedora/repository/', $thisPid, '/-/Collection/', 1)"/></xsl:attribute>
1 -...
</a>
</li>
</xsl:when>
<xsl:when test="($distanceFromCurrent = 5)">
<li class="pager-next">
<a>
<xsl:attribute name="href">
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $thisPid, '/-/Collection/', $totpage)"/>
</xsl:attribute>
<xsl:value-of select="concat('...- ', $count)"/>
</a>
</li>
</xsl:when>
</xsl:choose>
<!-- recursively call the template for all the paged sets -->
<xsl:if test="$pageIndex * $size < $count">
<xsl:call-template name="pageNumbers">
<xsl:with-param name="pageIndex" select="$pageIndex + 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="render_pager">
<!-- start previous next -->
<div class="item-list">
<ul class="pager">
<xsl:choose>
<xsl:when test="$end >= $count and $start = 1">
<!-- <xsl:value-of select="concat($start, '-', $count, ' of ', $count, ' ')"/><br /> -->
<xsl:call-template name="pageNumbers">
<xsl:with-param name="pageIndex" select="1"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$end >= $count">
<!-- <xsl:value-of select="concat($start, '-', $count, ' of ', $count, ' ')"/><br /> -->
<xsl:call-template name="pageNumbers">
<xsl:with-param name="pageIndex" select="1"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="$start = 1">
<!-- <xsl:value-of select="concat($start, '-', $count, ' of ', $count, ' ')"/><br /> -->
<xsl:call-template name="pageNumbers">
<xsl:with-param name="pageIndex" select="1"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<!-- <xsl:value-of select="concat($start, '-', $count, ' of ', $count, ' ')"/><br /> -->
<xsl:call-template name="pageNumbers">
<xsl:with-param name="pageIndex" select="1"/>
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</ul>
</div>
<!-- end previous next-->
</xsl:template>
<xsl:template match="s:result">
<xsl:variable name="OBJECTURI" select="s:object/@uri"/>
<xsl:variable name="CONTENTURI" select="s:content/@uri"/>
<xsl:variable name="CONTENTMODEL" select="substring-after($CONTENTURI,'/')"/>
<xsl:variable name="PID" select="substring-after($OBJECTURI,'/')"/>
<xsl:variable name="newTitle">
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="s:title"/>
<xsl:with-param name="from" select="'_'"/>
<xsl:with-param name="to" select="' '"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="cleanTitle" select="php:functionString('fedora_repository_urlencode_string', $newTitle)"/>
<xsl:variable name="linkUrl">
<xsl:choose>
<xsl:when test="($CONTENTMODEL='islandora:collectionCModel')">
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $PID, '/-/collection')"/>
</xsl:when>
<xsl:otherwise>
<!--the below is an example of going straight to a datastream instead of the details page.
<xsl:value-of select="$BASEURL"/>/fedora/repository/<xsl:copy-of select="$PID"/>/OBJ/<xsl:value-of select="s:title"/>-->
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $PID)"/>
</xsl:otherwise>
</xsl:choose>
<xsl:value-of select="s:content"/>
</xsl:variable>
<xsl:choose>
<xsl:when test="($CONTENTMODEL='islandora:collectionCModel')">
<td valign="top" width="25%">
<table class="collcell1">
<tr>
<td class="celldescr1">
<xsl:value-of select="$newTitle" disable-output-escaping="yes"/>
</td>
</tr>
<tr>
<td class="cellthumb1">
<a>
<xsl:attribute name="href">
<xsl:value-of select="$linkUrl"/>
</xsl:attribute>
<img>
<xsl:attribute name="src">
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $PID, '/TN')"/>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="$newTitle" disable-output-escaping="yes"/>
</xsl:attribute>
</img>
</a>
<!-- <br clear="all"/> -->
<xsl:if test="s:k0 > 0">
</xsl:if>
</td>
</tr>
</table>
</td>
</xsl:when>
<xsl:otherwise>
<td valign="top" width="25%">
<table class="collcell">
<tr>
<td class="cellthumb" height="250px">
<a>
<xsl:attribute name="href">
<xsl:value-of select="$linkUrl"/>
</xsl:attribute>
<img>
<xsl:attribute name="src">
<xsl:value-of select="concat($BASEURL, '/fedora/repository/', $PID, '/TN')"/>
</xsl:attribute>
<xsl:attribute name="alt">
<xsl:value-of select="$newTitle" disable-output-escaping="yes"/>
</xsl:attribute>
</img>
</a>
<br clear="all"/>
</td>
</tr>
<tr>
<td class="celldescr">
<xsl:choose>
<xsl:when test="($CONTENTMODEL='islandora:pageCModel')">
page <xsl:value-of select="substring-after($newTitle, '- page')" disable-output-escaping="yes"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$newTitle" disable-output-escaping="yes"/>
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
</table>
</td>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="(position() = last()) and (position() < $cellsPerRow)">
<xsl:call-template name="FillerCells">
<xsl:with-param name="cellCount" select="$cellsPerRow - position()"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="FillerCells">
<xsl:param name="cellCount"/>
<td> </td>
<xsl:if test="$cellCount > 1">
<xsl:call-template name="FillerCells">
<xsl:with-param name="cellCount" select="$cellCount - 1"/>
</xsl:call-template>
</xsl:if>
</xsl:template>
<xsl:template name="replace-string">
<xsl:param name="text"/>
<xsl:param name="from"/>
<xsl:param name="to"/>
<xsl:choose>
<xsl:when test="contains($text, $from)">
<xsl:variable name="before" select="substring-before($text, $from)"/>
<xsl:variable name="after" select="substring-after($text, $from)"/>
<xsl:variable name="prefix" select="concat($before, $to)"/>
<xsl:value-of select="$before"/>
<xsl:value-of select="$to"/>
<xsl:call-template name="replace-string">
<xsl:with-param name="text" select="$after"/>
<xsl:with-param name="from" select="$from"/>
<xsl:with-param name="to" select="$to"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
|
|