开发者

xsl with javascript

开发者 https://www.devze.com 2022-12-23 02:30 出处:网络
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 o

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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号