Search code examples
xslt-1.0dspace

Override recently added list in home page


I wonder if it's possible to override the Recently Added list in the home page. The default behavior is that any new submitted items are displayed in the list regardless of its issue date. Is there a way to override it such that only the latest submitted publications issued for example within two years (or a conditional if dc.date.issued => 2014) are displayed?

I am using DSpace 5.3 Mirage 2 theme.

UPDATE

Using @terry's answer, here is the code I tried:

<xsl:template match="dri:referenceSet[@rend='recent-submissions']">
    <xsl:for-each select="dri:reference">
        <xsl:variable name="externalMetadataURL">
            <xsl:text>cocoon:/</xsl:text>
            <xsl:value-of select="@url"/>
            <!-- No options selected, render the full METS document -->
        </xsl:variable>
        <xsl:comment> External Metadata URL: <xsl:value-of select="$externalMetadataURL"/> </xsl:comment>
        <xsl:variable name="issue-date"  select="document($externalMetadataURL)//dim:field[@element='date'][@qualifier='issued'][1]/text()"/>
        <xsl:comment> External Metadata URL: <xsl:value-of select="$issue-date"/> </xsl:comment>

        <!--
           Assuming dates conform to YYYY-MM-DD syntax, a simple string compare should work.
           An XSLT extension would be needed to computer the current date.
        -->
        <xsl:if test="$issue-date &lt; 2014">
            <xsl:apply-templates select="."/>
        </xsl:if>
    </xsl:for-each>
</xsl:template>

Also, as per suggestion of @schweerelos from my other post, I put a comment before the document() call to see if the metadata from the $externalMetadataURL were retrieved properly.

Viewing the source code in by browser, the metadata were retrieved properly (although it is not respecting my condition).

View Source

<div id="aspect_discovery_SiteRecentSubmissions_div_site-home" class="ds-static-div primary repository">
    <h2 class="ds-div-head page-header">Recently Added</h2>
    <div id="aspect_discovery_SiteRecentSubmissions_div_site-recent-submission" class="ds-static-div secondary recent-submission">
    <!-- External Metadata URL: cocoon://metadata/handle/10862/2260/mets.xml-->
    <!-- External Metadata URL: 2015-->
    <!-- External Metadata URL: cocoon://metadata/handle/10862/2265/mets.xml-->
    <!-- External Metadata URL: 2015-->
    <!-- External Metadata URL: cocoon://metadata/handle/10862/2261/mets.xml-->
    <!-- External Metadata URL: 2015-->
    <!-- External Metadata URL: cocoon://metadata/handle/10862/2262/mets.xml-->
    <!-- External Metadata URL: 2015-->
    <!-- External Metadata URL: cocoon://metadata/handle/10862/2263/mets.xml-->
    <!-- External Metadata URL: 2015-->
<p id="aspect_discovery_SiteRecentSubmissions_p_recent-submission-view-more" class="ds-paragraph recentSubmissionViewMore">
<a href="/recent-submissions">View more</a>

And this is the DRI generated:

<div id="aspect.discovery.SiteRecentSubmissions.div.site-home" rend="primary repository" n="site-home">
    <div id="aspect.discovery.SiteRecentSubmissions.div.site-recent-submission" rend="secondary recent-submission" n="site-recent-submission">
        <head>Recently Added</head>
        <referenceSet id="aspect.discovery.SiteRecentSubmissions.referenceSet.site-last-submitted" rend="recent-submissions" n="site-last-submitted" type="summaryList">   
            <reference repositoryID="10862" type="DSpace Item" url="/metadata/handle/10862/2260/mets.xml"/>
            <reference repositoryID="10862" type="DSpace Item" url="/metadata/handle/10862/2265/mets.xml"/>
            <reference repositoryID="10862" type="DSpace Item" url="/metadata/handle/10862/2261/mets.xml"/>
            <reference repositoryID="10862" type="DSpace Item" url="/metadata/handle/10862/2262/mets.xml"/>
            <reference repositoryID="10862" type="DSpace Item" url="/metadata/handle/10862/2263/mets.xml"/>
        </referenceSet>
        <p id="aspect.discovery.SiteRecentSubmissions.p.recent-submission-view-more" rend="recentSubmissionViewMore" n="recent-submission-view-more">
            <xref target="/recent-submissions">View more</xref>
        </p>
    </div>
</div>

Even if I remove my condition (eg <xsl:if test="$issue-date &lt; 2014">), I'm still having blanks as the View Source code and the image below shows.

recently added

Any advice please?


Solution

  • The DSpace config file for recent items (discovery.xml) will allow you to set the metadata field that is used to pull recent items. You can alter that field from collection to collection. You can set the maximum number of items to pull, but you cannot set other filter criteria.

    You will need to set that criteria in your XSLT using logic like the following.

    <xsl:template match="dri:referenceSet[@rend='recent-submission']">
       <xsl:for-each select="dri:reference">
         <xsl:variable name="issue-date"  select="document(@url)//dim:field[@element='date'][@qualifier='issued'][1]/text()"/>
    
        <!-- 
           Assuming dates conform to YYYY-MM-DD syntax, a simple string compare should work.
           An XSLT extension would be needed to computer the current date.
        -->
        <xsl:if test="$issue-date &gt; 2014">
          <ul class="ds-artifact-list">
            <xsl:apply-templates select="*[not(name()='head')]" mode="summaryList"/>
          </ul>
        </xsl:if>
      <xsl:for-each>
    </xsl:template>
    

    The following stackoverflow answer indicates how to incorporate a java function into a DSpace XSLT stylesheet: See How to shorten filename displayed in DSpace