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.
Related
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>
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>
I can declare a variable “myVariable” with a value “111” in the global scope.
But how can I re-assign a value locally. Or is there a alternative way to achieve this.
Please help.
Thank you.
Ravi
You can re-define the same variable inside a template:
<xsl:variable name="myVariable" select="'111'"/>
<xsl:template match="/">
<xsl:variable name="myVariable" select="'112'"/>
. . .
</xsl:template>
Note though that 'variables' in XSLT are actually constant - you are not re-assigning a different value to the same variable, you are re-defining it inside the template - outside the template myVariable will still have the value 111.
You can accomplish what you want to do, by using jscript/vbscript. Here is example using Jscript.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns="http://www.w3.org/TR/xhtml1/strict"
xmlns:msxsl='urn:schemas-microsoft-com:xslt'
xmlns:var='urn:var'
xmlns:JS='urn:JS'
>
<xsl:output method="html"/>
<xsl:variable name="n" select="1"/>
<xsl:template match="/NewDataSet">
<html>
<head>
<style>
table{border-collapse:collapse}
table,td{border:1px solid black;color:black; background-color:white}
table,th{border:1px solid balck;background-color:black;color:white }
.rt{color:red}
.redb{color:yellow; background-color:red;}
.greenb{color:white;background-color:green;}
</style>
<title>EDI validation Result </title>
</head>
<body>
<div font="bold">
EDI validation result for the PO <xsl:value-of select="info/pono"/>
</div>
<div>
received from <xsl:value-of select="info/CustomerName"/>
</div>
<xsl:variable name='var:hasErrors' select='0'/>
<xsl:variable name='var:ngoodlines' select='0' />
<xsl:variable name='var:nbadlines' select='0' />
<table>
<th>Position</th>
<th>Item Code</th>
<th>UoM</th>
<th>Ordered Qty.</th>
<th>Net-Quoted</th>
<th>Net-Catalog</th>
<th>Status</th>
<xsl:for-each select="Table">
<tr>
<xsl:choose>
<xsl:when test="Status !=''">
<xsl:value-of disable-output-escaping="yes" select="JS:IncBlines()"/>
<td class="redb"><xsl:value-of select="Position"/></td>
<td class="redb"><xsl:value-of select="ItemCode"/></td>
<td class="redb"><xsl:value-of select="UoM"/></td>
<td class="redb"><xsl:value-of select="QtyOrdered"/></td>
<td class="redb"><xsl:value-of select="PriceQuoted"/></td>
<td class="redb"><xsl:value-of select="Net"/></td>
<td class="redb"><xsl:value-of select="Status"/></td>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="JS:IncGlines()"/>
<td class="greenb"><xsl:value-of select="Position"/></td>
<td class="greenb"><xsl:value-of select="ItemCode"/></td>
<td class="greenb"><xsl:value-of select="UoM"/></td>
<td class="greenb"><xsl:value-of select="QtyOrdered"/></td>
<td class="greenb"><xsl:value-of select="PriceQuoted"/></td>
<td class="greenb"><xsl:value-of select="Net"/></td>
<td class="greenb"><xsl:value-of select="Status"/>OK</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
<xsl:if test="JS:GetBlines() > 0" >
<div class="rt">
<p>
The order validation has failed ,
The order will not be processesed as there are <xsl:value-of select ="JS:GetBlines()"/> lines in error.
<xsl:if test="JS:GetGlines() > 0">
Although there are <xsl:value-of select="JS:GetGlines()"/> line item(s) are that comply the requirements, <p>
The P.O is rejected as per agreed processing rules.
</p>
</xsl:if>
</p>
</div>
</xsl:if>
<xsl:value-of select="JS:GetBlines()"/>
<xsl:value-of select ="JS:GetGlines()"/>
</body>
</html>
</xsl:template>
<msxsl:script language='JScript' implements-prefix='JS'>
<![CDATA[
var j :int=0;
var blines:int =0;
var glines:int=0;
function Inc(current)
{j=j+current;
return j+current;
}
function IncBlines()
{
blines++;
}
function IncGlines()
{
glines++;
}
function GetBlines()
{
return blines;
}
function GetGlines()
{
return glines;
}
]]>
</msxsl:script>
</xsl:stylesheet>
<NewDataSet>
<Table>
<Position>1</Position>
<ItemCode>691-301-004</ItemCode>
<QtyOrdered>1</QtyOrdered>
<PriceQuoted>0.00</PriceQuoted>
<Net>0.0000</Net>
<UoM>EA</UoM>
<Status>Not in Catalog</Status>
</Table>
<Table>
<Position>2</Position>
<ItemCode>106284-133</ItemCode>
<QtyOrdered>1</QtyOrdered>
<PriceQuoted>20.00</PriceQuoted>
<Net>0.0000</Net>
<UoM>EA</UoM>
<Status>Not in Catalog</Status>
</Table>
<Table>
<Position>3</Position>
<ItemCode>116304-317</ItemCode>
<QtyOrdered>1</QtyOrdered>
<PriceQuoted>25.00</PriceQuoted>
<Net>0.0000</Net>
<UoM>EA</UoM>
<Status>Not in Catalog</Status>
</Table>
<Table>
<Position>4</Position>
<ItemCode>574116-035</ItemCode>
<QtyOrdered>10</QtyOrdered>
<PriceQuoted>1598.85</PriceQuoted>
<Net>1865.5000</Net>
<QtyApplicable>99999999</QtyApplicable>
<UoM>EA</UoM>
<Status>Quoted Price does not match Catalog price</Status>
</Table>
<Table>
<Position>5</Position>
<ItemCode>110223-301</ItemCode>
<QtyOrdered>10</QtyOrdered>
<PriceQuoted>147.88</PriceQuoted>
<Net>147.8800</Net>
<QtyApplicable>99999999</QtyApplicable>
<UoM>EA</UoM>
</Table>
<info>
<baanid>xxx-xxxxxx</baanid>
<pono>xxx0002987</pono>
<CustomerName>[xxx-xxxxxx]-xxxxxxxxxxxxxxxxxxxxxxxxx x xxxxx/CustomerName>
</info>
</NewDataSet>
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>