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>
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 have a problem on grouping elements based on a criteria and eliminating the duplicates.
I have 2 records in XML. Document 1 and Document 2
The objective is to create a table with 3 sections. Same, Add, Delete. Elements both in the record should come in Same subsection with their quantities. Element which is not there in Doc 1 and present in Doc 2 should come into Add subsection and Elements which is there in Doc 1 and not present in Doc 2 should come into Delete subsection.
Here i am able to create 3 subsections with their total. Now my problem is to identify the similar elements based on rec_no in the same document and sum their quantities.
Here is the output table with my comments.
---------------------------------------------------------
Section RecNo Desc Doc-1 Qty Doc-2 Qty Total
---------------------------------------------------------
Same 111 Desc1 1 2 300
Same 444 Desc4 6 4 1000
---------------------------------------------------------
Same Total 1300
---------------------------------------------------------
Add 333 Desc3 3 0 300
Add 555 Desc5 5 0 500
---------------------------------------------------------
Add Total 800
---------------------------------------------------------
Delete 222 Desc2 0 2 200
Delete 777 Desc7 0 7 700
Delete 888 Desc8 0 10 1000
---------------------------------------------------------
Delete Total 1900
---------------------------------------------------------
Grand Total 4000
---------------------------------------------------------
Here is my XML
<Logia>
<DocHeader>
<Document>
<Downto>
<rec_no>111</rec_no>
<desc>Desc1</desc>
<qty>1</qty>
<Value>100.00</Value>
</Downto>
<Downto>
<rec_no>333</rec_no>
<desc>Desc3</desc>
<qty>3</qty>
<Value>300.00</Value>
</Downto>
<Downto>
<rec_no>444</rec_no>
<desc>Desc4</desc>
<qty>6</qty>
<Value>400.00</Value>
</Downto>
<Downto>
<rec_no>555</rec_no>
<desc>Desc5</desc>
<qty>5</qty>
<Value>500.00</Value>
</Downto>
</Document>
<Document>
<Downto>
<rec_no>222</rec_no>
<desc>Desc2</desc>
<qty>2</qty>
<Value>200.00</Value>
</Downto>
<Downto>
<rec_no>111</rec_no>
<desc>Desc1</desc>
<qty>2</qty>
<Value>100.00</Value>
</Downto>
<Downto>
<rec_no>444</rec_no>
<desc>Desc4</desc>
<qty>4</qty>
<Value>400.00</Value>
</Downto>
<Downto>
<rec_no>777</rec_no>
<desc>Desc7</desc>
<qty>7</qty>
<Value>700.00</Value>
</Downto>
<Downto>
<rec_no>888</rec_no>
<desc>Desc8</desc>
<qty>8</qty>
<Value>800.00</Value>
</Downto>
<Downto>
<rec_no>888</rec_no>
<desc>Desc8</desc>
<qty>2</qty>
<Value>800.00</Value>
</Downto>
</Document>
</DocHeader>
</Logia>
and here is my XSLT
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:key name="doc1" match="Document[1]/Downto" use="rec_no" />
<xsl:key name="doc2" match="Document[2]/Downto" use="rec_no" />
<xsl:template match="/Logia/DocHeader">
<table border="1">
<!-- header -->
<tr>
<th>Section</th>
<th>RecNo</th>
<th>Desc</th>
<th>Doc-1 Qty</th>
<th>Doc-2 Qty</th>
<th> Total</th>
</tr>
<!-- same -->
<xsl:variable name="same" select="Document[1]/Downto[key('doc2', rec_no )]" />
<xsl:apply-templates select="$same">
<xsl:with-param name="section">Same</xsl:with-param>
</xsl:apply-templates>
<xsl:variable name="same-total" select="sum($same/Value)" />
<tr>
<td colspan="5">Same Total</td>
<th><xsl:value-of select="$same-total"/></th>
</tr>
<!-- add -->
<xsl:variable name="add" select="Document[1]/Downto[not(key('doc2', rec_no ))]" />
<xsl:apply-templates select="$add">
<xsl:with-param name="section">Add</xsl:with-param>
</xsl:apply-templates>
<xsl:variable name="add-total" select="sum($add/Value)" />
<tr>
<td colspan="5">Add Total</td>
<th><xsl:value-of select="$add-total"/></th>
</tr>
<!-- delete -->
<xsl:variable name="delete" select="Document[2]/Downto[not(key('doc1', rec_no ))]" />
<xsl:apply-templates select="$delete">
<xsl:with-param name="section">Delete</xsl:with-param>
</xsl:apply-templates>
<xsl:variable name="delete-total" select="sum($delete/Value)" />
<tr>
<td colspan="5">Delete Total</td>
<th><xsl:value-of select="$delete-total"/></th>
</tr>
<!-- grand total -->
<tr>
<th colspan="5">Grand Total</th>
<th><xsl:value-of select="$same-total + $add-total + $delete-total"/></th>
</tr>
</table>
</xsl:template>
<xsl:template match="Downto">
<xsl:param name="section"/>
<tr>
<td><xsl:value-of select="$section"/></td>
<td><xsl:value-of select="rec_no"/></td>
<td><xsl:value-of select="desc"/></td>
<td><xsl:value-of select="qty"/></td>
<td><xsl:value-of select="qty"/></td>
<td><xsl:value-of select="Value"/></td>
</tr>
</xsl:template>
</xsl:stylesheet>
Any help is appreciated.
There is not much to change in your code:
New key:
<xsl:key name="docByRecNo" match="Document/Downto" use="rec_no" />
Modify template that matches Downto:
<xsl:template match="Downto">
<xsl:param name="section"/>
<xsl:if test="generate-id() = generate-id(key('docByRecNo', rec_no)[1])">
<tr>
<td><xsl:value-of select="$section"/></td>
<td><xsl:value-of select="rec_no"/></td>
<td><xsl:value-of select="desc"/></td>
<td><xsl:value-of select="sum(key('doc1', rec_no)/qty)"/></td>
<td><xsl:value-of select="sum(key('doc2', rec_no)/qty)"/></td>
<td><xsl:value-of select="sum(key('docByRecNo', rec_no)/Value)"/></td>
</tr>
</xsl:if>
</xsl:template>
Here we select only those Downto records that are the first elements in group with the same rec_no (Muench grouping).
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>
To whom it may concern:
I created an xml file called affiliateReport.xml.config. Its purpose is to pull orders that match an affiliate so that an affiliate may view their orders. To test it I wanted the orders to be listed in the lat_account.aspx file for now. Unforatunately at this time it will only show me orders for AffiliateID equal to 0. Thus I know I'm hitting the database, and I know it it showing me the data but it won't show me the data based on the affiliateID of the affiliate login. Any help would be greatly appreciated. These files are from AspDotNetStoreFront Multistore. My code is below.
AffiliateReport.xml.config
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<package version="2.1" displayname="Affiliate Report" debug="false" includeentityhelper="true" allowengine="true">
<query name="AffiliateReport" rowElementName="AffiliateOrders">
<sql>
<![CDATA[
SELECT * from Orders with (NOLOCK)
LEFT JOIN Affiliate on Affiliate.AffiliateID = Orders.AffiliateID
WHERE Orders.AffiliateID = #affiliateID
]]>
</sql>
<queryparam paramname="#affiliateID" paramtype="runtime" requestparamname="AffiliateID" sqlDataType="int" defvalue="0" validationpattern="^\d{1,10}$" />
</query>
<PackageTransform>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf">
<xsl:output method="html" omit-xml-declaration="yes" />
<xsl:param name="LocaleSetting" select="/root/Runtime/LocaleSetting" />
<xsl:param name="WebConfigLocaleSetting" select="/root/Runtime/WebConfigLocaleSetting" />
<xsl:param name="XmlPackageName" select="/root/System/XmlPackageName" />
<xsl:param name="AffiliateID" select="/root/Runtime/WebConfigLocaleSetting" />
<xsl:template match="/">
<table width="90%">
<tr>
<td>Order Number</td>
<td width="10px"> </td>
<td>Affiliate ID</td>
<td width="10px"> </td>
<td>Total</td>
</tr>
<xsl:for-each select="/root/AffiliateReport/AffiliateOrders">
<tr>
<td><xsl:value-of select="OrderNumber" /></td>
<td> </td>
<td><xsl:value-of select="AffiliateID" /></td>
<td> </td>
<td>$<xsl:value-of select="OrderTotal" /></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>
</PackageTransform>
</package>
From lat_account.aspx line 313 I added the following code
<asp:Literal ID="XmlPackage_AffiliateOrders" runat="server" Mode="PassThrough" />
From lat_account.aspx.cs line 168 I added the following code
XmlPackage_AffiliateOrders.Text = AppLogic.RunXmlPackage ("affiliatereport.xml.config", base.GetParser, ThisCustomer, SkinID, String.Empty, String.Format("AffiliateID={0}", AffiliateID), true, true);
Thank you in advance!
Are you positive you are passing the correct value for Affiliate Id? My guess is the variable is not correctly set. You should attempt to debug at that line where you are setting the id.
Alternatively, you could set it manually to a different valid affiliate id
XmlPackage_AffiliateOrders.Text = AppLogic.RunXmlPackage ("affiliatereport.xml.config", base.GetParser, ThisCustomer, SkinID, String.Empty, String.Format("AffiliateID={0}", 5), true, true);
Add this to the top of lat_account.aspx:
<%# Register Src="~/controls/XmlPackageControl.ascx" TagName="XmlPackage" TagPrefix="adnsf" %>
Add this to lat_account.aspx where you want your XmlPackage to render:
<adnsf:XmlPackage runat="server" PackageName="AffiliateReport.xml.config" ID="AffiliateReportPackage" />
Add this to the Page_Load method of lat_account.aspx.cd after the lines where the AffiliateID variable has been populated:
AffiliateReportPackage.RuntimeParams = string.Format("LoggedInAffiliateID={0}", AffiliateID);
Change your xmlpackage sql parameter to this:
<queryparam paramname="#affiliateID" paramtype="runtime" requestparamname="LoggedInAffiliateID" sqlDataType="int" defvalue="0" validationpattern="" />
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>