Override recently added list in home page

大城市里の小女人 提交于 2019-12-04 05:10:59

问题


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.

Any advice please?


回答1:


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




回答2:


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.




回答3:


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>


来源:https://stackoverflow.com/questions/32263468/override-recently-added-list-in-home-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!