views:

326

answers:

1

I have tried every solution I found on here and even a larger Google search but nothing seems to work. Here is my problem... I have data that is in XML that I would like to visualize using the Google Visualization API. I was hoping I could simply use XSL to generate what I need instead of doing anything with data sources (I have my reasons). But the javascript code does not show up in my output. Is this even possible?

My XML

<DocumentElement>
  <QueryResults>
    <Year>2000</Year>
    <Population>100000</Population>
  </QueryResults>
  <QueryResults>
    <Year>2001</Year>
    <Population>105000</Population>
  </QueryResults>
</DocumentElement>

My XSL file

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="/">

    <script type="text/javascript" src="http://www.google.com/jsapi"&gt;&lt;/script&gt;     
    <script type="text/javascript">
     google.load('visualization', '1', {packages:['barchart']});
     google.setOnLoadCallback(drawChart);

     function drawChart() {
      var data = new google.visualization.DataTable();

      data.addColumn('string', 'Year');
      data.addColumn('string', 'Population');
      data.addRows(2); // hard-coded for testing

      <xsl:for-each select="DocumentElement/QueryResults">
       data.setValue(0, 0, '<xsl:value-of select="Year"/>');
       data.setValue(0, 1, '<xsl:value-of select="Population"/>');     
      </xsl:for-each>

      var chart = new google.visualization.BarChart(document.getElementById('chart_div'));
      chart.draw(data, {width: 400, height: 240, is3D: true, title: 'Population'});
     }
    </script>

    <div id="chart_div">&#160;</div>

</xsl:template>
</xsl:stylesheet>

My output

<!-- notice no javascript -->
<div id="chart_div"> </div>
+2  A: 
Chris Doggett
What I pasted is exactly what the XML output I have to work with looks like. Then a 3rd party component renders based on the XML and my XSL... It sounds like I might have to dig into the renderer to find out what is going on. Thanks.
NJChim
Which 3rd party component, if you don't mind my asking? Like I mentioned, I just copied your inputs to test.xml and test.xsl and added the stylesheet directive, and it works, so you're on the right track. I think it's probably just something with your toolchain.
Chris Doggett
It is XML spit out from the DNN reports module and I am seeing if I can use the built-in XSL visualization. I have it working using the HTML visualizer but it is ugly. And if you are not familiar with DNN then this probably means nothing to you. :)
NJChim