/ Published in: MXML

I found this blog that explained how AIR can transform XML using XSLT. http://blogs.adobe.com/briggs/2008/05/using_air_for_xslt_processing.html
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?xml version="1.0" encoding="utf-8"?> <mx:WindowedApplication xmlns:mx ="http://www.adobe.com/2006/mxml" creationComplete ="init()" width ="640" height ="800" horizontalAlign ="left" viewSourceURL="srcview/index.html"> <mx:Script> <![CDATA[ import mx.controls.*; private var html:HTMLLoader = new HTMLLoader(); private function init():void { // Load the HTML page that has the JS that we'll use to // do the XSLT. var urlReq:URLRequest = new URLRequest("xslt.html"); html.load(urlReq); // Assign some sample content to the text boxes. xmlArea.text = sampleXML; xslArea.text = sampleXSL; } private function process():void { var doProcess:Boolean = true; try { // Validate the input XML. var xml:XML = new XML(xmlArea.text); if (xml == null || xml.toXMLString().length == 0) { Alert.show("Please enter some XML to transform."); doProcess = false; } } catch (e:Error) { Alert.show("The XML to transform is malformed."); doProcess = false; } if (doProcess) { try { // Validate the input XSLT. var xsl:XML = new XML(xslArea.text); if (xsl == null || xsl.toXMLString().length == 0) { Alert.show("Please enter an XSLT document."); doProcess = false; } } catch (e:Error) { Alert.show("The XSLT document is malformed."); doProcess = false; } } if (doProcess) { // Call into the JS to do the actual transformation. outputArea.text = html.window.transformXML(xml,xsl); } else { outputArea.text = null; } } private var sampleXML:XML = <report-types> <report-type>Report 1</report-type> <report-type>Report 2</report-type> <report-type>Report 3</report-type> </report-types>; private var sampleXSL:XML = <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:template match="/report-types"> <table> <tr> <th>Options</th> </tr> <tr> <xsl:for-each select="report-type"> <td><xsl:value-of select="."/></td> </xsl:for-each> </tr> </table> </xsl:template> </xsl:stylesheet>; ]]> </mx:Script> <mx:Label text ="XML to transform:"/> <mx:TextArea id ="xmlArea" height ="30%" width ="100%"/> <mx:Label text ="XSLT document:"/> <mx:TextArea id ="xslArea" height ="35%" width ="100%"/> <mx:Label text ="Output of transformation:"/> <mx:TextArea id ="outputArea" text ="" height ="30%" width ="100%"/> <mx:HBox width ="100%" horizontalAlign ="center"> <mx:Button id ="button" label ="Process" click ="process()"/> </mx:HBox> </mx:WindowedApplication>
Comments
