1

Below is my 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 to pass the XSL variable PassCount like that below:

var data = google.visualization.arrayToDataTable([
          ['Task', 'Hours per Day'],
          ['Work',     passcount],
          ['Eat',      2],
          ['Commute',  2],
          ['Watch TV', 2],
          ['Sleep',    7]
        ]);

Is there any smart way to do this?

10
  • Hope some one will Help Me pls ! Commented Apr 5, 2013 at 8:22
  • Does this help: stackoverflow.com/questions/6166994/… Commented Apr 5, 2013 at 8:32
  • Hi Friend Matpol,Tx for the help.But its not the solution. :-( Commented Apr 5, 2013 at 9:10
  • passcount is in a loop? is that why is doesn't work? Commented Apr 5, 2013 at 9:29
  • hi matpol,yep its in a loop is there a way to access it then ? Commented Apr 5, 2013 at 10:03

1 Answer 1

1

Hopefully I answer to your question (I not really sure, but anyway)

There should be no problem to generate javascript with xslt, if you don't use CDATA. Than you can use xsl:value-of to put xslt var values at any position you like. But without CDATA you have to escap some chars (<,&) in your 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],
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Hr_117,i found the issue.its because of calling a variable out from a loop.any way thank you tooo for your great effort.KIT .. Lahiru
can some one give an answear for this theard pls.stackoverflow.com/questions/16568531/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.