Skip to content

Instantly share code, notes, and snippets.

@eulereadgbe
Last active March 4, 2020 04:08
Show Gist options
  • Save eulereadgbe/52401d5ae1ce290398dd59ae4eaf75f1 to your computer and use it in GitHub Desktop.
Save eulereadgbe/52401d5ae1ce290398dd59ae4eaf75f1 to your computer and use it in GitHub Desktop.
Added top 10 most downloaded items to /statistics-home
<xsl:template match="dri:div[@id='aspect.statistics.StatisticsTransformer.div.home' and @n='home']//dri:table[@id='aspect.statistics.StatisticsTransformer.table.list-table' and @rend='tableWithTitle detailtable']">
<xsl:variable name="statsURL" select="confman:getProperty('solr-statistics.server')"/>
<xsl:apply-templates select="document(concat($statsURL,'/select?q=type:2+-isBot:true+statistics_type:view&amp;wt=xml&amp;indent=true&amp;facet=true&amp;facet.field=id&amp;facet.sort=count&amp;facet.limit=10'))" mode="most-visited"/>
<xsl:apply-templates select="document(concat($statsURL,'/select?q=type:0+-isBot:true+statistics_type:view&amp;wt=xml&amp;indent=true&amp;facet=true&amp;facet.field=owningItem&amp;fq=bundleName:ORIGINAL&amp;facet.sort=count&amp;facet.limit=10'))" mode="most-downloaded"/>
</xsl:template>
<xsl:template match="/" mode="most-downloaded">
<h3 class="ds-table-head">Total Downloads</h3>
<div class="table-responsive">
<table class="ds-table table table-striped table-hover tableWithTitle detailtable">
<tbody>
<tr class="ds-table-row">
<th class="ds-table-header-cell labelcell">&#160;</th>
<th class="ds-table-header-cell labelcell">Downloads</th>
</tr>
<xsl:for-each select="/response/lst/lst/lst[@name='owningItem']/int">
<tr class="ds-table-row">
<xsl:variable name="searchURL" select="confman:getProperty('discovery','search.server')"/>
<td class="most_downloaded ds-table-cell labelcell">
<xsl:variable name="itemId">
<xsl:value-of select="./@name"/>
</xsl:variable>
<xsl:apply-templates select="document(concat($searchURL,'/select?q=*:*&amp;fl=title,handle&amp;wt=xml&amp;omitHeader=true&amp;indent=true&amp;fq=search.resourceid:',$itemId))" mode="itemMeta"/>
</td>
<td class="downloaded_count ds-table-cell labelcell">
<xsl:value-of select="format-number(text(),'#,###')"/>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</div>
</xsl:template>
<xsl:template match="/" mode="most-visited">
<h3 class="ds-table-head">Total Visits</h3>
<div class="table-responsive">
<table class="ds-table table table-striped table-hover tableWithTitle detailtable">
<tbody>
<tr class="ds-table-row">
<th class="ds-table-header-cell labelcell">&#160;</th>
<th class="ds-table-header-cell labelcell">Views</th>
</tr>
<xsl:for-each select="/response/lst/lst/lst[@name='id']/int">
<tr class="ds-table-row">
<xsl:variable name="searchURL" select="confman:getProperty('discovery','search.server')"/>
<td class="most_downloaded ds-table-cell labelcell">
<xsl:variable name="itemId">
<xsl:value-of select="./@name"/>
</xsl:variable>
<xsl:apply-templates select="document(concat($searchURL,'/select?q=*:*&amp;fl=title,handle&amp;wt=xml&amp;omitHeader=true&amp;indent=true&amp;fq=search.resourceid:',$itemId))" mode="itemMeta"/>
</td>
<td class="downloaded_count ds-table-cell labelcell">
<xsl:value-of select="format-number(text(),'#,###')"/>
</td>
</tr>
</xsl:for-each>
</tbody>
</table>
</div>
</xsl:template>
<xsl:template match="/" mode="itemMeta">
<xsl:variable name="mainURL" select="confman:getProperty('dspace.baseUrl')"/>
<a>
<xsl:attribute name="href"><xsl:value-of select="concat($mainURL,'/handle/',/response/result/doc/str[@name='handle']/text())"/></xsl:attribute>
<xsl:for-each select="/response/result/doc/arr[@name='title']/str">
<xsl:value-of select="./text()"/>
</xsl:for-each>
</a>
</xsl:template>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment