Am using xslt to convert QTP generated xml results. Here when I click on the TestPlan (link) , all the testcases under that test plan node should get displayed as a table. So I use call template inside anchor tag. But Call Template is not being called. Here is my sample xslt code.
You can't call an xslt template from javascript; xslt is rendered on the server, whereas the javascript is client side. That xslt would give you a result of something like
<a href="#" onClick="<h1>[attrDisplay value]</h1>"> author name </a>
You would be better of calling the Display_Case template to start with and making it invisible, then using the click event to show the output as necessary
As Euan says, you're trying to do something that isn't possible the way you think it is - you use XSLT to generate the HTML that gets sent to the browser; so the XSLT is executed on the server.
You need to implement the show/hide stuff using JavaScript, and then attach that function to the onclick-attribute - XSLT can help you with the dynamic parts of that, e.g.:
You see? displayCase is the JavaScript function to execute. The bolded part is called an "Attribute Value Template" and it works like the <xsl:value-of /> instruction, but inside of an attribute (so you don't need the <xsl:attribute> construct for simple stuff like this)
I understand that I have to use Javascript and inside that i can form table with tha combinatyion of xsl and diaplay the content.
Here, <ahref="#"onclick="displayCase('{bookstore/book/@category}')"> will be passed as a javascript variable, and inside javascript, I have to assign this javascript variable toxsl variable for conditioning purposes.
Is it possible to assign javascript variable to an xsl variable.
I tried as below. This is a javascript function I use in XSL style sheet.
function testCaseSummary(suiteId) { var caseID ; alert(suiteId); var testCaseTable = '<table border = "1" width = "100%"><tr bgcolor = "Aqua"><th width = "5%">S.No</th><th width ="35%">Testcase Name</th><th width = "15%">Status</th><th width = "20%">Time</th></tr>'; var testCaseRow = '<xsl:variable name="xslsuiteID">"+suiteId+"</xsl:variable>';
You cannot call xslt from javascript. You cannot use a function in javascript to then process xslt.
You need to do this on 2 seperate steps
1- Use xslt to render out all the necessary markup on the page. This is the stage where you can hide the markup that you don't want immediately displayed.
2- Use javascript to show/hide the markup as necessary
I worked on that and now I resolved calling a template from javascript.Its working.
But now I face another problem inside for each loop. xsl code is as below. In that inside template " Action_Summary ", DName is printed for all the "Doc" inside "Report" tag. But I haveused the if condition. I don know where am wrong.
Calling a template on clicking a link.
Hi,
Am using xslt to convert QTP generated xml results. Here when I click on the TestPlan (link) , all the testcases under that test plan node should get displayed as a table. So I use call template inside anchor tag. But Call Template is not being called. Here is my sample xslt code.
Kindly help me on this.
Code
*******************
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:template match="/">
<html>
<script language="javascript" type="text/javascript">
function testPlanSummary() {
alert("sdsdd");
}
</script>
<body>
<h2>Click below link</h2>
<A href = "#">
<xsl:attribute name="onClick">
<xsl:call-template name="Display_Case">
<xsl:with-param name="AttrDisplay"><xsl:value-of select="bookstore/book/@category"/></xsl:with-param>
</xsl:call-template>
</xsl:attribute>
<xsl:value-of select="bookstore/book/author"/>
</A>
</body>
</html>
</xsl:template>
<xsl:template name="Display_Case">
<xsl:param name="AttrDisplay"/>
<h1><xsl:value-of select = "$AttrDisplay"/></h1>
</xsl:template>
</xsl:stylesheet>
You can't call an xslt template from javascript; xslt is rendered on the server, whereas the javascript is client side. That xslt would give you a result of something like
<a href="#" onClick="<h1>[attrDisplay value]</h1>"> author name </a>
You would be better of calling the Display_Case template to start with and making it invisible, then using the click event to show the output as necessary
Thanks. But cam u please tell how to make the template visible on click event. or is there any other workaround..?
Hi nagarajan,
As Euan says, you're trying to do something that isn't possible the way you think it is - you use XSLT to generate the HTML that gets sent to the browser; so the XSLT is executed on the server.
You need to implement the show/hide stuff using JavaScript, and then attach that function to the onclick-attribute - XSLT can help you with the dynamic parts of that, e.g.:
You see? displayCase is the JavaScript function to execute. The bolded part is called an "Attribute Value Template" and it works like the <xsl:value-of /> instruction, but inside of an attribute (so you don't need the <xsl:attribute> construct for simple stuff like this)
/Chriztian
Thanks.
I understand that I have to use Javascript and inside that i can form table with tha combinatyion of xsl and diaplay the content.
Here, <ahref="#"onclick="displayCase('{bookstore/book/@category}')"> will be passed as a javascript variable, and inside javascript, I have to assign this javascript variable toxsl variable for conditioning purposes.
Is it possible to assign javascript variable to an xsl variable.
I tried as below. This is a javascript function I use in XSL style sheet.
function testCaseSummary(suiteId) { var caseID ; alert(suiteId); var testCaseTable = '<table border = "1" width = "100%"><tr bgcolor = "Aqua"><th width = "5%">S.No</th><th width ="35%">Testcase Name</th><th width = "15%">Status</th><th width = "20%">Time</th></tr>'; var testCaseRow = '<xsl:variable name="xslsuiteID">"+suiteId+"</xsl:variable>';
testCaseRow += '<xsl:for-each select="Project/TestSuite"><xsl:if test="@TestSuiteID = $xslsuiteID"><xsl:for-each select="TestCase"><tr><center><td><xsl:value-of select="@TestCaseID"/></td></center>';
Is this possible...?
You cannot call xslt from javascript. You cannot use a function in javascript to then process xslt.
You need to do this on 2 seperate steps
1- Use xslt to render out all the necessary markup on the page. This is the stage where you can hide the markup that you don't want immediately displayed.
2- Use javascript to show/hide the markup as necessary
I worked on that and now I resolved calling a template from javascript.Its working.
But now I face another problem inside for each loop. xsl code is as below. In that inside template " Action_Summary ", DName is printed for all the "Doc" inside "Report" tag. But I haveused the if condition. I don know where am wrong.
Kindly help me.
function testPlanSummary(id) {
alert(id);
var callTemplate = '<xsl:variable name="aID">';
callTemplate += id;
callTemplate += '</xsl:variable>';
callTemplate += '<xsl:call-template name="Action_Summary"><xsl:with-param name="AttrDisplay"><xsl:value-of select= "$aID"/></xsl:with-param></xsl:call-template>';
alert(callTemplate);
top.right.document.getElementById("TestPlan").innerHTML = callTemplate;
}
<xsl:template name="Action_Summary">
<xsl:for-each select="Report/Doc">
<xsl:if test="DIter/Action/@rID = 'T4'">
<h1><xsl:value-of select="DName"/></h1>
</xsl:if>
</xsl:for-each>
</xsl:template>
You can't call an xslt template from javascript.
I suggest you use the xslt to render all the necessary html on the page (hiding any if necessary).
Then use javascript, to hide/show the elements as required
is working on a reply...