I have inherited some xslt code that isn't working correctly. I have examined it and looked at various questions here and elsewhere, but still can't isolate the issue. There are numerous links through the code which attempt to use the xslt variable link_value. Everywhere it is referenced it is in the format '{$link_value}', and here is where confusion starts. In some answers here, it is stated that the variable must be in braces, and in others, the braces are not there. Some say no quotes around it and some show quotes. link_value is a string and needs the quotes when it is referenced. The value that is being placed in link_value is in the corresponding XML. And then there is the scoping issue, for which I have seen numerous answers, all contradictory. Can someone tell me why link_value wont expand properly?
link_value references //companyheader/title which is also referenced on line 195 and shows up correctly on the web page.
Also, there is a $("#roatitle").click(function() entry (at line 176) which also uses link_value. this entry gives me a pointer on the web page, but when I click on it nothing happens. The entry on line 180 has the same issue. Any help on this one?
I compressed the XML to keep it small and only show the revelant data.
chartsdatareport.XML:
<chartsdatareport>
<privateroaroeratiosdata>
<datapoint></datapoint>
</privateroaroeratiosdata>
<privateincomeratiosdata>
<datapoint></datapoint>
</privateincomeratiosdata>
<companyheader>
<id>300902</id>
<title>Bank of America NA</title>
<address>100 N Tryon St, Ste 170 </address>
<citystatezip>Charlotte, NC 28202</citystatezip>
<phone>(980) 335-3561</phone>
<fax>(704) 386-0981</fax>
<internetaddress>www.bankofamerica.com</internetaddress>
</companyheader>
<financial>
</financial>
<bankinsightrating>
</bankinsightrating>
<financialsummary>
</financialsummary>
<loancomposition>
</loancomposition>
<depositscomposition>
</depositscomposition>
</chartsdatareport>
I wanted to include all of the code for scoping purposes, but had to remove a bunch of style sheet code to keep it small.
PrivateChartsDataReport.xslt:
<?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" encoding="utf-8" indent="yes"/>
<xsl:template match="/chartsdatareport">
<xsl:text disable-output-escaping="yes"><!DOCTYPE html></xsl:text>
<html>
<head>
<title>Company Tearsheet</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
var roeValues = [];
var roaValues = [];
var netIncomeValues = [];
var netInterestIncomeValues = [];
var roaroequarters = [];
var incomequarters = [];
var tier1riskbasedcapital = [];
var totalriskbasedcapital = [];
var toteqtytotassets = [];
var corecaploanlossres = [];
var IntGrowthRateEqtyCap = [];
var leverage = [];
var tangcommequity = [];
var totalinterestincome = [];
var totalinterestexpense = [];
var noninterestincome = [];
var overheadexpense = [];
var nplgrossloans = [];
var npatotalassets = [];
var ncoavgloans = [];
var reservesgrossloans = [];
var totalloansnet = [];
var avgearnasst = [];
var nonintbearingdeposits = [];
var totalnonearningassets = [];
var date = [];
var ratingTA=<xsl:value-of select="//bankinsightrating/ratingta"/>;
var rating = [<xsl:value-of select="//bankinsightrating/peers"/>, <xsl:value-of select="//bankinsightrating/regional"/>, <xsl:value-of select="//bankinsightrating/national"/>];
var revertrating = [<xsl:value-of select="100-//bankinsightrating/peers"/>, <xsl:value-of select="100-//bankinsightrating/regional"/>, <xsl:value-of select="100-//bankinsightrating/national"/>];
<xsl:apply-templates select="privateroaroeratiosdata"/>
<xsl:apply-templates select="privateincomeratiosdata"/>
var entitytype="<xsl:value-of select="//companyheader/entitytype"/>";
var chartroaroe;
var chartnetincome;
var loan;
var deposits;
var capitalAdequacy1;
var capitalAdequacy2;
var capitalAdequacyCU1;
var capitalAdequacyCU2;
var profitabilityRatios1;
var profitabilityRatios2;
var assetQuality1;
var assetQuality2;
var liquidity1;
var liquidity2;
<xsl:text disable-output-escaping="yes">
<![CDATA[
function addCommas(str) {
var amount = new String(str);
amount = amount.split("").reverse();
var output = "";
for ( var i = 0; i <= amount.length-1; i++ ){
output = amount[i] + output;
if ((i+1) % 3 == 0 && (amount.length-1) !== i)output = ',' + output;
}
return output;
}
function formatRating(val) {
if (val == 0 && ratingTA == 0 && entitytype=='Holding Company'){
return '<span style="font-size:20px">N/A</span>';
} else {
return '<span style="color:white">'+val+'</span>';
}
}
]]>
</xsl:text>
$(document).ready(function() {
chartrating = new Highcharts.Chart({
chart: {
renderTo: 'rating',
type: 'column',
backgroundColor: '#666666',
margin: 0,
spacingBottom: 5,
spacingLeft: 0,
spacingRight: 0
},
credits: {
enabled: false
},
exporting: {
buttons: {
exportButton: {
enabled: false
},
printButton: {
enabled: false
}
}
},
title: {
text: 'Banking Insight Rating',
style: {
display: 'none'
}
},
xAxis: {
categories: rating,
gridLineWidth: 0,
minorGridLineWidth: 0,
lineColor: 'transparent',
lineWidth: 0,
tickLength: 0,
minorTickLength: 0,
labels: {
enabled: true,
style: {
font: 'bold 26px Verdana',
color: '#FFFFFF'
},
y: -35,
formatter: function(){
return formatRating(this.value);
}
}
},
yAxis: {
gridLineWidth: 0,
lineWidth: 0,
min: 0,
max: 100,
labels: {
enabled: false
},
title: {
text: '',
margin: 0
}
},
plotOptions: {
column: {
stacking: 'normal',
borderWidth: 0,
point: {
events: {
mouseOut: function(){
$("#ratingtooltip").hide();
},
mouseOver: function(){
$("#ratingtooltip").show();
}
}
}
},
series: {
pointWidth: 50
}
},
tooltip: {
enabled: false
},
legend:{
enabled: false
},
series: [{
color: '#005A84',
data: revertrating
},{
color: '#FF9100',
data: rating
}]
});
$("#roatitle").click(function(){
parent.getHighlineTop().newTab('/bats/company/PopupReport.do?entityID=<xsl:value-of select="//companyheader/id"/><xsl:text disable-output-escaping="yes"><![CDATA[&report=DYRPT%3A%3A118]]></xsl:text>','{$link_value}');
});
$("#incometitle").click(function(){
parent.getHighlineTop().newTab('/bats/company/PopupReport.do?entityID=<xsl:value-of select="//companyheader/id"/><xsl:text disable-output-escaping="yes"><![CDATA[&report=EXCEL%3A%3A621]]></xsl:text>','{$link_value}');
});
});
</script>
</head>
<body>
<script src="/bats/highcharts/highcharts.js"></script>
<script src="/bats/highcharts/modules/exporting.js"></script>
<script src="/bats/js/uiUtilBats.js"></script>
<table cellpadding="0" cellspacing="0" border="0" width="100%" class="bg">
<tr>
<td class="companyheader" vAlign="top">
<div class="companytitle"><xsl:value-of select="//companyheader/title"/></div>
<div class="top5"><xsl:value-of select="//companyheader/address"/></div>
<div><xsl:value-of select="//companyheader/citystatezip"/></div>
<div>Phone: <xsl:value-of select="//companyheader/phone"/></div>
<div>Fax: <xsl:value-of select="//companyheader/fax"/></div>
<div>
<a target="_blank">
<xsl:attribute name="href">http://<xsl:value-of select="//companyheader/internetaddress"/></xsl:attribute>
<xsl:value-of select="//companyheader/internetaddress"/>
</a>
</div>
</td>
<td>
<div id="zero1">($000)</div>
</td>
<td class="rating">
<table cellpadding="0" cellspacing="0" border="0" width="100%">
<tr>
<td class="ratingtitle">
<a href="javascript:void(0)">
<xsl:attribute name="onclick">parent.getHighlineTop().newTab('/bats/company/PopupReport.do?entityID=<xsl:value-of select="//companyheader/id"/>&report=EXCEL%3A%3A401','{$link_value}')</xsl:attribute>
Bank Insight Rating</a></td>
</tr>
<tr>
<td class="ratinglink">
<a href="#" onclick="parent.getHighlineTop().newTab('/banking/pages/bpages/ratingmethod.html', 'BankInsight Rating Methodology')">
Rating Methodology</a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colspan="3" class="menu">
<table align="center" border="0" cellpadding="0" cellspacing="0" width="87%" >
<tr>
<xsl:choose>
<xsl:when test="//companyheader/entitytype != 'Credit Union'">
<td align="left" width="33%">
<a href="javascript:void(0)">
<xsl:attribute name="onclick">parent.getHighlineTop().newTab('/bats/company/PopupReport.do?entityID=<xsl:value-of select="//companyheader/id"/>&report=5','{$link_value}')</xsl:attribute>
M&A Activity</a></td>
</xsl:when>
<xsl:otherwise>
<td align="left" width="33%">
<a href="javascript:void(0)">
<xsl:attribute name="onclick">parent.getHighlineTop().newTab('/bats/company/PopupReport.do?entityID=<xsl:value-of select="//companyheader/id"/>&report=DYRPT%3A%3A20','{$link_value}')</xsl:attribute>
Peer Group Data</a></td>
</xsl:otherwise>
</xsl:choose>
<td align="center" width="33%">
<a href="javascript:void(0)">
<xsl:attribute name="onclick">parent.getHighlineTop().newTab('/bats/company/PopupReport.do?entityID=<xsl:value-of select="//companyheader/id"/>&report=1000','{$link_value}')</xsl:attribute>
Market Share Data</a></td>
<xsl:choose>
<xsl:when test="//companyheader/entitytype != 'Credit Union'">
<td align="right" width="33%">
<a href="javascript:void(0)">
<xsl:attribute name="onclick">parent.getHighlineTop().newTab('/bats/company/PopupReport.do?entityID=<xsl:value-of select="//companyheader/id"/>&report=41','{$link_value}')</xsl:attribute>
Company Hierarchy</a></td>
</xsl:when>
<xsl:otherwise>
<td align="right" width="33%">
<a href="javascript:void(0)">
<xsl:attribute name="onclick">parent.getHighlineTop().newTab('/bats/company/PopupReport.do?entityID=<xsl:value-of select="//companyheader/id"/>&report=EXCEL%3A%3A365','{$link_value}')</xsl:attribute>
Income Analysis</a></td>
</xsl:otherwise>
</xsl:choose>
</tr>
</table></td>
</tr>
</table>
</body>
</html>
</xsl:template>
<xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="escapos">\'</xsl:variable>
<xsl:variable name="link_value">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="//companyheader/title"/>
<xsl:with-param name="replace" select="$apos"/>
<xsl:with-param name="by" select="$escapos"/>
</xsl:call-template>
</xsl:variable>
<xsl:template match="privateroaroeratiosdata">
<xsl:for-each select="./datapoint">
roeValues.push(<xsl:value-of select="./roevalue"/>);
roaValues.push(<xsl:value-of select="./roavalue"/>);
roaroequarters.push('<xsl:value-of select="./quarter"/>');
tier1riskbasedcapital.push(<xsl:value-of select="./tier1riskbasedcapital"/>);
totalriskbasedcapital.push(<xsl:value-of select="./totalriskbasedcapital"/>);
leverage.push(<xsl:value-of select="./leverage"/>);
tangcommequity.push(<xsl:value-of select="./tangcommequity"/>);
toteqtytotassets.push(<xsl:value-of select="./toteqtytotassets"/>);
corecaploanlossres.push(<xsl:value-of select="./corecaploanlossres"/>);
IntGrowthRateEqtyCap.push(<xsl:value-of select="./IntGrowthRateEqtyCap"/>);
totalinterestincome.push(<xsl:value-of select="./totalinterestincome"/>);
totalinterestexpense.push(<xsl:value-of select="./totalinterestexpense"/>);
noninterestincome.push(<xsl:value-of select="./noninterestincome"/>);
overheadexpense.push(<xsl:value-of select="./overheadexpense"/>);
nplgrossloans.push(<xsl:value-of select="./nplgrossloans"/>);
npatotalassets.push(<xsl:value-of select="./npatotalassets"/>);
ncoavgloans.push(<xsl:value-of select="./ncoavgloans"/>);
reservesgrossloans.push(<xsl:value-of select="./reservesgrossloans"/>);
totalloansnet.push(<xsl:value-of select="./totalloansnet"/>);
avgearnasst.push(<xsl:value-of select="./avgearnasst"/>);
nonintbearingdeposits.push(<xsl:value-of select="./nonintbearingdeposits"/>);
totalnonearningassets.push(<xsl:value-of select="./totalnonearningassets"/>);
</xsl:for-each>
</xsl:template>
<xsl:template match="privateincomeratiosdata">
<xsl:for-each select="./datapoint">
netIncomeValues.push(<xsl:value-of select="./netincome"/>);
netInterestIncomeValues.push(<xsl:value-of select="./netinterestincome"/>);
incomequarters.push('<xsl:value-of select="./quarter"/>');
</xsl:for-each>
</xsl:template>
<xsl:template name="string-replace-all">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text, $replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text"
select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="by" select="$by"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
Here is snippet from another of our codes where this works fine. But I think due to all of the code being together:
<tr class="evenrow"><td>Top Holding Company:</td>
<td>
<xsl:variable name="apos">'</xsl:variable>
<xsl:variable name="escapos">\'</xsl:variable>
<xsl:variable name="link_value">
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="TOP_HC_NAME" />
<xsl:with-param name="replace" select="$apos"/>
<xsl:with-param name="by" select="$escapos"/>
</xsl:call-template>
</xsl:variable>
<xsl:choose>
<xsl:when test="TOP_HC!=''">
<xsl:value-of select="TOP_HC_NAME" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="TOP_HC_NAME" />
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
thanks in advance for your assistance.
The XPath expression to extract the value of a variable is $variableName with no quotes, but the question is which places in the stylesheet are interpreted as XPath expressions and which aren't.
In attribute values on literal result elements you can include XPath expressions in braces and they will be evaluated, this is called "attribute value template" syntax. This is the situation with something like
<a onclick="topHC('{TOP_HC}','{$link_value}')">
where TOP_HC and $link_value are XPath expressions, and the single quotes surrounding these will come through literally in the output and will form part of the resulting JavaScript expression.
But in situations like
<xsl:attribute name="onclick">parent.getHighlineTop().newTab('...','{$link_value}')</xsl:attribute>
you are not in an attribute value template, and the {$link_value} is output literally rather than being treated as an XPath expression. To evaluate XPaths in this situation you need to use value-of. It may be clearer to wrap the literal segments in xsl:text so you can break the lines in the XSLT without introducing newlines into the result:
<xsl:attribute name="onclick">
<xsl:text>parent.getHighlineTop().newTab('...','</xsl:text>
<xsl:value-of select="$link_value"/>
<xsl:text>')</xsl:text>
</xsl:attribute>
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 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>
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>