我继承了一些无法正常工作的xslt代码。我已经检查了它并在这里和其他地方查看了各种问题,但仍然无法隔离问题。通过代码有许多链接尝试使用xslt变量link_value。它被引用的地方都是' {$ link_value}',这里是混乱开始的地方。在这里的一些答案中,声明变量必须在括号中,而在其他情况下,括号不在那里。有人说它周围没有引号,有些则显示引号。 link_value是一个字符串,在引用时需要引号。 link_value中的值位于相应的XML中。然后是范围问题,我看到了许多答案,都是矛盾的。有人能告诉我为什么link_value不会正常扩展?
link_value引用// companyheader / title,它也在第195行引用并在网页上正确显示。
此外,还有$("#roatitle")。click(function()条目(第176行)也使用了link_value。这个条目在网页上给了我一个指针,但是当我点击它没有任何反应。第180行的条目也有同样的问题。对此有任何帮助吗?
我压缩了XML以使其保持较小并仅显示重要数据。 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>
我想包含所有用于作用范围的代码,但是必须删除一堆样式表代码以保持它的小。 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>
以下是我们其他代码的代码段,其中此方法正常。但我认为由于所有代码都在一起:
<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!=''">
<a href="javascript:void(0)" onclick="topHC('{TOP_HC}','{$link_value}')"><xsl:value-of select="TOP_HC_NAME" /></a>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="TOP_HC_NAME" />
</xsl:otherwise>
</xsl:choose>
</td>
</tr>
提前感谢您的帮助。
答案 0 :(得分:1)
提取变量值的XPath表达式是$variableName
,没有引号,但问题是样式表中的哪些位置被解释为XPath表达式,哪些不是。
在文字结果元素的属性值中,您可以在大括号中包含XPath表达式并对它们进行评估,这称为&#34;属性值模板&#34;句法。这是类似
的情况<a onclick="topHC('{TOP_HC}','{$link_value}')">
其中TOP_HC
和$link_value
是XPath表达式,围绕这些表达式的单引号将在输出中逐字显示,并将构成生成的JavaScript表达式的一部分。
但在像
这样的情况下<xsl:attribute name="onclick">parent.getHighlineTop().newTab('...','{$link_value}')</xsl:attribute>
在属性值模板中不,{$link_value}
按字面输出,而不是被视为XPath表达式。要在这种情况下评估XPath,您需要使用value-of
。将文字段包装在xsl:text
中可能更清楚,这样您就可以在XSLT中打破行而不在结果中引入换行符:
<xsl:attribute name="onclick">
<xsl:text>parent.getHighlineTop().newTab('...','</xsl:text>
<xsl:value-of select="$link_value"/>
<xsl:text>')</xsl:text>
</xsl:attribute>