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 < 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">
View more
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 < 2014">), I'm still having blanks as the View Source code and the image below shows.
Any advice please?
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 > 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
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.
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>
Related
In any other language I could just store the previous row's value in a variable and then see if it matches the current value or not, but alas variables in XSL aren't really "variable" or something like that...
So, how do I accomplish what should be an otherwise 'easy' task?
I have some (probably poorly formed) XML, output by a third-party application. I use it to ouput each of the following lines as html table rows using XSL:
<xsl:for-each select="Designs/TrackingDetails/Details">
<tr>
<th width="200"><xsl:value-of select="./#DGGroup"/></th>
<th width="350"><xsl:value-of select="./#DGName"/></th>
<td><xsl:value-of select="./#DGDate"/></td>
<td><xsl:value-of select="./#DGUser"/></td>
</tr>
</xsl:for-each>
What I would like is for it to only print each unique 'DGGroup' once, but it either prints all of them, or nothing at all.
So, in the end, I'd like HTML like this (using XML similar to the bottom of my post):
<tr><td>General</td><td>Quote in Date</td><td>04/16/2015</td><td>Ed Garcia</td></tr>
and on the next line:
<tr><td></td><td>Bid Complete</td><td>04/12/2015</td><td>John Smith</td></tr>
Here's some code I've tried so far:
<xsl:if test="preceding-sibling::./DGGroup[1]=self::./DGGroup">
AND
<xsl:if test="preceding-sibling::*[1]=./#DGGroup">
...Neither of which work
Here is a sample of some of the XML:
<Designs>
<TrackingDetails Transactions_Id="2" Reference="A1234">
<Details DGGroup="General" DGName="Quote in Date" DGDate="04/16/2015" DGUser="Ed Garcia" />
<Details DGGroup="General" DGName="Bid Complete" DGDate="04/12/2015" DGUser="John Smith" />
<Details DGGroup="Design" DGName="Approval Recieved" DGDate="" DGUser="" />
<Details DGGroup="Design" DGName="Design Complete" DGDate="09/18/2015" DGUser="Fred Smith" />
<Details DGGroup="Production" DGName="Released to Production" DGDate="09/18/2015" DGUser="Fred Smith" />
<Details DGGroup="Production" DGName="At Printers" DGDate="" DGUser="" />
<Details DGGroup="Production" DGName="Packaged" DGDate="" DGUser="" />
<Details DGGroup="Delivery" DGName="Delivery Packet Made" DGDate="09/18/2015" DGUser="Fred Smith" />
<Details DGGroup="Invoice" DGName="Invoiced" DGDate="" DGUser="" />
</TrackingDetails>
Any ideas? TIA!
Here is one way to do it.
First group the results by DGGroup
Then print the group name only when position = 1
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes"/>
<xsl:key name="groups" match="/TrackingDetails/Details" use="#DGGroup" />
<xsl:template match="/TrackingDetails">
<table id="Details">
<tr class="heading">
<th scope="col">DGGroup</th>
<th scope="col">DGName</th>
<th scope="col">DGDate</th>
<th scope="col">DGUser</th>
</tr>
<xsl:apply-templates select="Details[generate-id() = generate-id(key('groups', #DGGroup)[1])]"/>
</table>
</xsl:template>
<xsl:template match="Details">
<xsl:for-each select="key('groups', #DGGroup)">
<tr>
<xsl:choose>
<xsl:when test="position()=1">
<td><xsl:value-of select="#DGGroup"/></td>
</xsl:when>
<xsl:otherwise>
<td></td>
</xsl:otherwise>
</xsl:choose>
<td><xsl:value-of select="#DGName"/></td>
<td><xsl:value-of select="#DGDate"/></td>
<td><xsl:value-of select="#DGUser"/></td>
</tr>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
I would like to add extra class to the Comment section in the Feedback form. Using Mirage 2 theme, the HTML looked like this:
<div class="control-group col-sm-12">
<label for="aspect_artifactbrowser_FeedbackForm_field_comments" class="control-label">Comments: </label>
<textarea rows="5" cols="20" onkeydown="event.cancelBubble=true;" onfocus="javascript:tFocus(this);" name="comments" class="ds-textarea-field form-control" id="aspect_artifactbrowser_FeedbackForm_field_comments"> </textarea>
</div>
I want to add an extra class eg <div class="myClass control-group col-sm-12">
In preprocess.xsl, I have this code:
<xsl:template match="dri:field[#id='aspect.artifactbrowser.FeedbackForm.field.comments' and #n='comments' and #type='textarea']" priority="3">
<div class="myClass">
<xsl:apply-templates/>
</div>
</xsl:template>
But the above code returns this HTML below:
<div class="control-group col-sm-12">
<div class="ds-static-div">Comments</div>
</div>
which is just displaying the word Comments
What is wrong with my xsl:template match?
The preprocess step is a DRI to DRI transformation, not a DRI to HTML transformation.
If you want to capture a dri:field and just add an attribute to it, do it like this:
<xsl:template match="dri:field[#id='aspect.artifactbrowser.FeedbackForm.field.comments' and #n='comments' and #type='textarea']" priority="3">
<field>
<xsl:call-template name="copy-attributes"/>
<xsl:attribute name="rend">
<xsl:value-of select="#rend" />
<xsl:text> myClass</xsl:text>
</xsl:attribute>
<xsl:apply-templates/>
</field>
</xsl:template>
rend is usually the attribute that gets mapped to class by the theme. But you may want to look up exactly which template in the theme will be applied to that specific dri:field.
Do you know how to get only "ADH6170" in xslt 1.0
Thanks.
<h2>
ADH6170
<strong>
Bayan kol saati
</strong>
</h2>
<xsl:template match="h2">
<xsl:value-of select="//text()" />
</xsl:template>
Is there any way to split the content as well as the attribute value using XSLT.
My input will look like:
<element id=”value1, value2, value3”>value1; value2; value3</element>
and the required output is"
<a href=”#value1”>value1</a>; <a href=”#value2”>value2</a>; <a href=”#value3”>value3</a>
Help me the possible way to do this in XSLT.
Thanks in advance
Try
<xsl:template match="element[#id]">
<xsl:variable name="att-values" select="tokenize(#id, ', ')"/>
<xsl:for-each select="tokenize(., '; ')">
<xsl:variable name="pos" select="position()"/>
<xsl:if test="position() gt 1"><xsl:text>; </xsl:text></xsl:if>
<a href="#{$att-values[$pos]}">
<xsl:value-of select="."/>
</a>
</xsl:for-each>
</xsl:template>
I have a value in xslt and I need to put it into the data-time attribute of the p tag
<xsl:value-of select="current()/eventTime" />
<p class="time" data-time="1">Duration: <xsl:value-of select="current()/eventTime" /> hour(s)</p>
this creates an error
<p class="time" data-time="<xsl:value-of select="current()/eventTime" />">Duration: <xsl:value-of select="current()/eventTime" /> hour(s)</p>
any idea how I achieve this?
"Attribute Value Templates" are your friend here
<p class="time" data-time="{current()/eventTime}">
Duration: <xsl:value-of select="current()/eventTime" /> hour(s)
</p>
The curly braces indicate that this is an Attribute Value Template, and so contains an expression to be evaluated.
Note that an alternate way would be to use the xsl:attribute element
<p class="time">
<xsl:attribute name="data-time">
<xsl:value-of select="current()/eventTime" />
</xsl:attribute>
Duration: <xsl:value-of select="current()/eventTime" /> hour(s)
</p>
This is not so elegant though. You would only really need to do it this way if wanted a dynamic attribute name.
Something like this?
<xsl:variable name="eventtime" select="current()/eventTime"/>
<xsl:element name="p">
<xsl:attribute name="class">time</xsl:attribute>
<xsl:attribute name="data-time">
<xsl:value-of select="$eventtime" />
</xsl:attribute>
Duration:
<xsl:value-of select="$eventtime" />
</xsl:element>
instead of <xsl:attribute> it's also possible to use the short form in '{}' brackets. In your case it would be like this:
<xsl:value-of select="current()/eventTime" />
<p class="time" data-time="{$eventtime}">Duration: <xsl:value-of select="current()/eventTime" /> hour(s)</p>