4 Replies Latest reply on Apr 15, 2008 6:20 AM by gizmogwai

    How to use xslt in AIR?


      I'm discovering AIR and I'm looking for XSL Transformation trough AIR.

      I first try to set the initial window to may xml file, refering to an internal xsl stylesheet, but as a result, I only get the raw XML file, without the transformation.
      I've then set the path to the xsl file to "app:/my_file.xsl" but it does not change anything.

      So, what is the way to refer to an internal xsl stylesheet?

      Thanks for your advices.
        • 1. Re: How to use xslt in AIR?
          Admiral_Brodnack Level 1
          Using an XML file instead of an HTML file doesn't seem to work (and I haven't seen any docs for AIR that state that it SHOULD work). However, you can transform your XML into HTML with XSLT using JavaScript and then display it:

          <script src="AIRAliases.js"></script>
          function loadXMLDoc(filename)
          xmlFile = air.File.applicationDirectory;
          xmlFile = xmlFile.resolvePath(filename);
          stream = new air.FileStream();
          stream.open(xmlFile, air.FileMode.READ);
          xmlDoc = stream.readUTFBytes(stream.bytesAvailable);
          var domParser = new DOMParser();
          xmlDoc = domParser.parseFromString(xmlDoc, "text/xml");
          return xmlDoc

          function displayResult()
          xsltProcessor=new XSLTProcessor();
          resultDocument = xsltProcessor.transformToFragment(xml,document);
          <body id="example" onLoad="displayResult()">

          (replace books.xml and books.xsl with your own files, obviously.)
          • 2. Re: How to use xslt in AIR?
            Admiral_Brodnack Level 1
            For reference, here is my XSL file:
            <?xml version="1.0" encoding="UTF-8"?>
            <xsl:stylesheet version="1.0" xmlns:xsl=" http://www.w3.org/1999/XSL/Transform">
            <xsl:template match="/">
            <h2>Fairly Odd Books </h2>

            <xsl:template match="books">
            <ul id="booklist">

            <xsl:template match="book">
            <li><em><xsl:value-of select="title"/></em> by <xsl:value-of select="author"/></li>

            And the XML file:
            <?xml version="1.0" encoding="utf-8" ?>
            <author>Boffo, Biff</author>
            <title>The Flying Circus</title>
            <author>Zantu, Obergaow</author>
            <title>Far-off Places</title>
            • 3. Re: How to use xslt in AIR?
              gizmogwai Level 1
              Thanks for your answer.
              Looking at the Wekbit API I came to the same conclusion. I was also trying to use Document.load method, but it seems that Webkit is the only engine that does not implement it yet.
              • 4. Re: How to use xslt in AIR?
                gizmogwai Level 1
                Hum... I've another problem now. I need to do some regexp transformation from the xml content.
                I've tried to use the exslt regexp extension, but it is not present in webkit, and add the script in the xsl doesn't help neither (the function is not found by the xslt processor).

                So, I tryed to define a "replace" function in the sandbox and place some <script>replace(...)</script> in the xsl. The problem is that the <script> tag are well translated by the xslt processor, but not interpretate when appending the fragment to the document. Is there a way to tell to indicate to webkit that he should also execute the content of the script tag?