1

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?

Community
  • 1
  • 1
euler
  • 1,401
  • 2
  • 18
  • 39

3 Answers3

2

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

Community
  • 1
  • 1
terrywb
  • 3,740
  • 3
  • 25
  • 50
  • Terry, instead of using a java function, I used `date:year()` function to compare if the issue date is equals current year. Of course I substring `$issue-date` first to return just the 4 digits. I noticed that `[@rend='recent-submission']` should be `[@rend='recent-submissions']` I already changed the metadata field in `discovery.xml` to date issued instead of date accessioned. My test condition looked like this: `` but I'm having blank results. Thanks in advance. – euler Aug 29 '15 at 09:42
  • I updated my post to include the actual code I used. The recent list is not displayed, please advice what is wrong with my code. Hoping for your positive response and thanks in advance. – euler Sep 01 '15 at 11:10
  • I do not understand what "having blanks" means. What happens if you add a comment into your block? Try comparing against '2014' instead of 2014. If I understood your initial question, I believe you will want a > test. – terrywb Sep 01 '15 at 16:50
  • I updated my post with image as to what "having blanks" mean. I add a comment ` External Metadata DATE: ` inside my `` block and the comment didn't show up when I view source. I increased my recentSubmissionConfiguration to 100 in `discovery.xml` thinking that maybe this is the reason why the list doesn't show up. In my initial question, I just put `>` as an arbitrary condition. I would like to test this if it is really respecting the condition that I set in the `` block. I also tried `'2014'` but same results. – euler Sep 01 '15 at 22:56
  • Before you added the template , did recent items appear? The call to should have returned what you were seeing previously. I am not familiar with the mirage2 theme. Can you find the code in mirage2 that displays recent items? Perhaps that will help to identify th problem. – terrywb Sep 01 '15 at 23:06
  • I just tried this using the default Mirage theme, I'm having the same results with Mirage2 theme. Yes, recent items appear before I added the template `` block. Even if I removed the `` block, recent items are not showing. – euler Sep 01 '15 at 23:19
  • 1
    In Mirage, I believe that this is the template that is called to show a recent item: https://github.com/DSpace/DSpace/blob/dspace-5_x/dspace-xmlui/src/main/webapp/themes/dri2xhtml-alt/aspect/artifactbrowser/common.xsl#L69-L84 You will need to replicate this logic inside your xsl:for-each. I suspect you will need to add a mode to the xsl:apply-templates call. – terrywb Sep 01 '15 at 23:38
  • Thanks a lot Terry! You are right, adding a mode solved my problem. I add `mode="summaryList"` and voila! – euler Sep 02 '15 at 03:16
1

Ok, for my future reference, the code below is what I used to override the recent submissions list in the homepage using Mirage 2 theme. Thanks to @terrywb for his answer.

<xsl:template match="dri:div[@id='aspect.discovery.SiteRecentSubmissions.div.site-recent-submission']/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:variable name="issue-date"  select="document($externalMetadataURL)//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="substring($issue-date,1,4) = date:year()">
            <xsl:comment> External Metadata URL: <xsl:value-of select="$issue-date"/> </xsl:comment>
            <xsl:comment> Current year is: <xsl:value-of select="date:year()"/> </xsl:comment>
            <ul class="ds-artifact-list list-unstyled">
                <xsl:apply-templates select="." mode="summaryList"/>
            </ul>
        </xsl:if>
    </xsl:for-each>
</xsl:template>

Note that I used

<xsl:template match="dri:div[@id='aspect.discovery.SiteRecentSubmissions.div.site-recent-submission']/dri:referenceSet[@rend='recent-submissions']">

This is because if I just use <xsl:template match="dri:referenceSet[@rend='recent-submissions']">, it will also override the list after you clicked the View more link. I also used the date:year() XSLT extension to capture the current year so that I don't have to hardcode or change the year every year.

Community
  • 1
  • 1
euler
  • 1,401
  • 2
  • 18
  • 39
1

I changed 'Recently Added' modifying these code block in page-strucutre.xsl:

<!-- Otherwise use default handling of body -->
<xsl:otherwise>
    <xsl:apply-templates />
</xsl:otherwise>

By this:

<!-- Otherwise use default handling of body -->
<xsl:otherwise>
    <xsl:apply-templates select="*[not((@n='site-home'))]"/>
</xsl:otherwise>

This change will block render of 'Recently Added' and 'Community View'.

To show 'Recently Added' in other place on page-strucutre, I have create one template for this:

<xsl:template name="buildCustomRecent">
    <ul class="list-group-plain" style="list-style: none;">
        <xsl:variable name="countRecent">
            <xsl:value-of select="count(/dri:document/dri:body/dri:div/dri:div/dri:referenceSet/*)" />
        </xsl:variable>
        <xsl:for-each select="/dri:document/dri:body/dri:div/dri:div/dri:referenceSet/*">
            <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:variable name="title"
                          select="document($externalMetadataURL)//dim:field[@element='title'][not(@qualifier)]"/>
            <xsl:variable name="author"
                          select="document($externalMetadataURL)//dim:field[@element='contributor'][@qualifier='author'][1]/text()"/>
            <xsl:variable name="issue-date"
                          select="document($externalMetadataURL)//dim:field[@element='date'][@qualifier='issued'][1]/text()"/>
            <xsl:variable name="urlObjId" select="document($externalMetadataURL)//mets:METS/@OBJID"/>

            <li>
                <a>
                    <xsl:attribute name="href">
                        <xsl:value-of select="$urlObjId"/>
                    </xsl:attribute>
                    <xsl:value-of select="$title"/>
                </a>
                <br/>
                <xsl:value-of select="concat($author,' (',$issue-date,')')"/>
                <br/>
            </li>
        </xsl:for-each>
        <xsl:if test="$countRecent=0">
            <xsl:text>No itens to show.</xsl:text>
        </xsl:if>
    </ul>
</xsl:template>