I am using xsl to convert my xml file into a html file which includes a table. Once the table has been formed, Im calling an external javascript function which counts the number of failures occurred. Now based on the number of failures, I have to send the html file as an attachment with the email. I have been searching for different methods as to how to access the external javascript variable in xsl. I even tried few methods suggested when googling it out but in vain! I want "noOfOccurance" variable value to be passed to xsl file. Any help is much appreciated! Thank you!
Here is my xsl file :
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
>
<xsl:template match="/">
<html>
<head><title>Olahtek Automation</title></head>
<body>
<table border="1">
<tr>
<th style="color:Blue">TestCase</th>
<th style="color:Blue">Number Of Tests</th>
<th style="color:Blue">Failures</th>
<th style="color:Blue">Result</th>
</tr>
<xsl:for-each select="testsuites/testsuite">
<tr>
<td><xsl:value-of select="@name"/></td>
<td><xsl:value-of select="@tests"/></td>
<td><xsl:value-of select="@failures"/></td>
<xsl:choose>
<xsl:when test="@failures > 0">
<td style="color:red">Fail</td>
</xsl:when>
<xsl:otherwise>
<td style="color:green">Pass</td>
</xsl:otherwise>
</xsl:choose>
</tr>
</xsl:for-each>
</table>
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript"
src="/usr/lib/node_modules/protractor/ola_auto/count.js">
</script>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Here is my external javascript file - count.js
getOccurance("Fail");
function getOccurance(word)
{
$("table").each(function (tindx, tobj)
{
var noOfOccurance = 0;
$("tr td:gt(1)", $(tobj)).each(function (ind, obj)
{
if (word == $.trim($(obj).text())) noOfOccurance++;
});
document.write("Number Of Failures : " +noOfOccurance);
var cu = document.URL;
var lastPart = cu.split("/").pop();
document.write("<br>");
document.write("Test Case Name : " +lastPart);
})
}