XSL: Passing Javascript Variables across XSL Templates & Files
I am currently working with a set of XSL templates that are used for reporting. The issue I'm having is that my javascript variables are not being updated. I currently have includes at the top of the page, but the Javascript variables are defined underneath that. Could this be the problem? Where should I be defining these variables? Is there a special way to pass them between the XSL templates? Until now I have not been using any Javascript and I have only been working with XSL. However, I need to perform some calculations not and also need to update variables so I need to figure out how to get the variables moving between templates. Or is there even a way?
So in the below, there are function calls within some of the templates being called and there is also a statement which updates the start and end date values based on XSL values. The issue is that all that is being printed is the initial set values, not the updated values.
Any help to point me in the right direction would be great.
Thanks in advance!
<xsl:param name="DisplayEmptyFields" select="true()"/>
<xsl:template ma开发者_开发技巧tch="/">
<xsl:include href="./Templates/styles.xslt"/>
<xsl:include href="./Templates/md_GeneralReportTemplates.xslt"/>
<xsl:include href="./Templates/md_RunDetailReportTemplate.xslt"/>
<html>
<head>
<script type="text/javascript">
var d = "";
var startdate = "6/7/2100 10:56:34 AM";
var enddate = "6/7/2008 10:56:34 AM";
var totruns = 0;
var passedruns = 0;
var failedruns = 0;
var date.flag = 0;
function ticks(){
totruns++;
}
function passticks(){
passedruns++;
}
function failticks(){
failedruns++;
}
</script>
<xsl:call-template name="DefineStyles"/>
</head>
<body>
<xsl:call-template name="pageheader"/>
<xsl:apply-templates select="run"/>
</xsl:for-each>
<table xsl:use-attribute-sets="report-detail-table-format">
<tr xsl:use-attribute-sets="report-header-row-table-format">
<th colspan="4">
Summary
</th>
</tr>
<tr>
<td><b>Total Runs: </b><script type="text/javascript">document.write(totruns);</script></td>
<td><b>Passed Runs: </b><script type="text/javascript">document.write(passedruns);</script></td>
<td><b>Failed Runs: </b><script type="text/javascript">document.write(failedruns);</script></td>
<td><b>Pass Rate: </b><script type="text/javascript">document.write(Math.round((passedruns/totruns*100)*Math.pow(10,2))/Math.pow(10,2));</script>%</td>
</tr>
<tr>
<td colspan="2"><b>Execution Start: </b><script type="text/javascript">document.write(startdate);</script></td>
<td colspan="2"><b>Execution End: </b><script type="text/javascript">document.write(enddate);</script></td>
</tr>
</table>
</body>
</html>
As far as the XSLT stylesheet is concerned, your <script>
elements are just data, they are not executable code. You're confused about the processing model: the XSLT transformation is executed to produce an HTML page, and the HTML page is then loaded; the browser will typically trigger the onLoad event which will cause some of the Javascript on the page to execute. So you've got two completely separate things happening: an HTML page being generated, and the Javascript on that page being executed.
I see there is something wrong with that var date.flag = 0;
:
[2011-06-23 18:49:11] JavaScript
Inline script compilation
Syntax error at line 9 while loading:
var date.flag = 0;
--------------------^
expected ';', got '.'
This error makes your variables undefined. Try to comment/modify it and I guess it should be ok.
精彩评论