xslt - How to pass XSL variable in to a Javascript function? -


below sample xsl file

<?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt">     <xsl:template match="/">         <html>             <head>                 <script type="text/javascript">                 //<![cdata[                 function showhide(elementid){                     if (document.getelementbyid(elementid).style.display == 'none'){                         document.getelementbyid(elementid).style.display = '';                     } else {                         document.getelementbyid(elementid).style.display = 'none';                     }                 }                 //]]></script>                 <!-- inserting pie chart  -->                 <script type="text/javascript" src="https://www.google.com/jsapi"></script>                 <script type="text/javascript">                 //<![cdata[                 google.load("visualization", "1", {packages:["corechart"]});                 google.setonloadcallback(drawchart);                 function drawchart() {                     var data = google.visualization.arraytodatatable([                         ['task', 'hours per day'],                         ['work',     11],                         ['eat',      2],                         ['commute',  2],                         ['watch tv', 2],                         ['sleep',    7]                     ]);                      var options = {                         title: 'my daily activities'                     };                      var chart = new google.visualization.piechart(document.getelementbyid('chart_div'));                     chart.draw(data, options);                 }             //]]></script>             <!--finishing pie chrt -->             </head>             <body>                 <h2>ebuilder automation test suite-summary</h2>                 <div id="chart_div" style="width: 600px; height: 400px;"></div>                 <table border="1">                     <tr bgcolor="#808080">                         <th>name</th>                         <th>total tcs</th>                         <th>passed</th>                         <th>skipped</th>                         <th>errors</th>                         <th>failures</th>                         <th>pass rate</th>                         <th>tot time taken</th>                     </tr>                     <xsl:for-each select="testsuite">                         <xsl:variable name="passcount">                             <number>                                 <xsl:value-of select="(@tests - @skipped - @errors - @failures)"/>                             </number>                         </xsl:variable>                         <tr>                             <td>                                 <xsl:value-of select="@name"/>                             </td>                             <td>                                 <xsl:value-of select="@tests"/>                             </td>                              <td bgcolor="#32cd32">                                 <xsl:value-of select="(@tests - @skipped - @errors - @failures)"/>                             </td>                             <td bgcolor="#ffff00">                                 <xsl:value-of select="@skipped"/>                             </td>                             <td>                                 <xsl:value-of select="@errors"/>                             </td>                             <td bgcolor="#ff0000">                                 <xsl:value-of select="@failures"/>                             </td>                             <td>                                 <font color="red">                                     <xsl:value-of select="(msxsl:node-set($passcount)/number) div @tests * 100"/>%                                 </font>                              </td>                             <td bgcolor="#008000">                                 <xsl:value-of select="@time"/>                             </td>                             <!--xsl:value-of select="@failures div @tests *100"/-->                         </tr>                     </xsl:for-each>                 </table>             </body>         </html>     </xsl:template> </xsl:stylesheet> 

i want pass xsl variable passcount below:

var data = google.visualization.arraytodatatable([           ['task', 'hours per day'],           ['work',     passcount],           ['eat',      2],           ['commute',  2],           ['watch tv', 2],           ['sleep',    7]         ]); 

is there smart way this?

hopefully answer question (i not sure, anyway)

there should no problem generate javascript xslt, if don't use cdata. can use xsl:value-of put xslt var values @ position like. without cdata have escap chars (<,&) in javascript code.

 'work',     <xsl:value-of select="(msxsl:node-set($passcount)/number)/> ], 

or

var passcount = <xsl:value-of select="(msxsl:node-set($passcount)/number)/>; .... ['work',     passcount], 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -