I tried every solution found here and even a larger Google search, but nothing works. Here is my problem ... I have data that is in XML that I would like to render using the Google Visualization API. I was hoping I could just use XSL to generate what I needed, instead of doing anything with data sources (I have reasons). But javascript code is not showing up in my release. Is it 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">
<xsl:output method="html" encoding="utf-8"/>
<xsl:template match="/">
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<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);
<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"> </div>
</xsl:template>
</xsl:stylesheet>
My conclusion
<div id="chart_div"> </div>
source
share