我有一个JavaScript代码:
var data = google.visualization.arrayToDataTable([
['Year', 'Sales', 'Expenses'],
['2004', 1000, 400],
['2005', 1170, 460],
['2006', 660, 1120],
['2007', 1030, 540]
]);
现在我想在xml中重写它。这是我的尝试:
<title>Bar Chart - Company Performance</title>
<dataHeadings index=0>
<dataHeading index=0>Year</dataHeading>
<dataHeading index=1>Sales</dataHeading>
<dataHeading index=2>Expenses</dataHeading>
</dataHeadings>.......so on
这是对的吗?我把它作为一个5x3矩阵接近它,但它是5x3或更像5x1矩阵?我觉得我做错了。任何指导对此都有很大帮助。
答案 0 :(得分:1)
您可以尝试查看以下结构:
<performance>
<annual year="value" sales="value" expenses="value" />
<annual year="value" sales="value" expenses="value" />
<annual year="value" sales="value" expenses="value" />
</performance>
看到你的年份,销售和费用只是价值,你不会需要这样的结构:
<performance>
<annual>
<year>value</year>
<sales>value</sales>
<expenses>value</expenses>
</annual>
<annual>
<year>value</year>
<sales>value</sales>
<expenses>value</expenses>
</annual>
</performance>
顺便说一下,我认为属性必须是双引号。例如index =&#34; 1&#34;,而不是index = 1.
答案 1 :(得分:0)
根据http://www.w3schools.com/xsl/
这两种方法都是处理XML的方法......如果你试图用XSLT解析javascript数组,我不确定你会有多少运气。
但是,如果您只是想知道如何根据我的知识使用XSLT使数据可用,那将是:
<Objects>
<Object>
<Year>2004</Year>
<Sales>1000</Sales>
<Expenses>400</Expenses>
</Object>
<Object>
<Year>2005</Year>
<Sales>1170</Sales>
<Expenses>460</Expenses>
</Object>
<Object>
<Year>2006</Year>
<Sales>660</Sales>
<Expenses>1120</Expenses>
</Object>
<Object>
<Year>2007</Year>
<Sales>1030</Sales>
<Expenses>540</Expenses>
</Object>
</Objects>