tags:

views:

36

answers:

2

I've a file with xml data. And I want to generate a report out of it. I tried to integrate xsl with java script, but can I get a handle of individual data elements in xsl and pass it on to a java script function.

Lets say <value>true</value> is in the xml and I want to pass it on to a javascript function while doing something like this in xsl.

<xsl:for-each select="/valgroup">
<xsl:value-of select="value"/>
</xsl:for-each>

The alternative is to parse the xml in java script and get the values, I've got little idea of how to integrate it with xsl.

Are there any java script libraries. I've seen my libraries that run on servers(AJAXSLT), but I need something that runs locally.

I'm a new to xslt, so consider this a worthy question.

A: 

I've found this article particularly useful after working with it for sometime.

http://www.ibm.com/developerworks/xml/library/x-tipxsltjs/

If there's any other way of generating reports(open source way) from XML, then I'd like to know, since it'd make the task even more simpler.

Vignesh
+1  A: 

Most browsers have built in XSL functionality, here is a code snippet

//This bit creates an XSLT processor from a http request (you have to download it first)

xslProc = new XSLTProcessor();
xslProc.importStylesheet(http.responseXML);

You can then perform the transform like so

xslProc.input = xmlDoc;
xslProc.transform();
var output = xslProc.output;

xmlDoc is the XML file you wish to transform xslProc is the previously created XSLT Processor output is the result

Hope this helps

Chris