执行XML转换中的Flex [英] Performing XML Transformations in Flex

查看:116
本文介绍了执行XML转换中的Flex的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望能够在我的AIR项目运行使用XSLT文件的XML转换。什么是实现这一目标的最好方法是什么?

I'd like to be able to run an xml transformation using an xslt file in my AIR project. What's the best way to accomplish this?

推荐答案

在AIR 1.5,版本的Webkit与支持XSLT是包括在内。

In AIR 1.5, a version of Webkit with support for XSLT is included.

使用类 XSLTProcessor中从JavaScript就像你在Firefox。 (注:。有一个恼人的错误样式表不能包含非中断空格,无论从字面上还是作为一个字符引用,有人告诉我的Webkit的较新版本将解决这个问题)

Use the class XSLTProcessor from JavaScript just like you would in Firefox. (Note: There is one annoying bug. Stylesheets cannot contain non-breaking spaces, no matter whether literally or as a character reference. I am told that more recent versions of Webkit will fix this issue.)

下面是一个完整的例子。

Below is a complete example.

创建一个文件的test.html

<html>
  <head>
    <title>XSLT test</title>
    <script type="text/javascript">
      // <!--
      function test() {

        // Step 1: Parse the stylesheet
        var stylesheet
          = "<xsl:transform xmlns:xsl='http://www.w3.org/1999/XSL/Transform'"
          + "               version='1.0'>"
          + "  <xsl:template match='/'>"
          + "    Hello World from XSLT!"
          + "  </xsl:template>"
          + "</xsl:transform>";
        var stylesheetDocument
          = new DOMParser().parseFromString(stylesheet, "application/xml");

        // Step 2: Parse the source document
        var source = "<dummy/>";
        var sourceDocument
          = new DOMParser().parseFromString(source, "application/xml");

        // Step 3: Perform the XSL transformation
        var xslt = new XSLTProcessor();
        xslt.importStylesheet(stylesheetDocument);
        var newFragment = xslt.transformToFragment(sourceDocument, document);

        // Step 4: Show the result
        document.body.appendChild(newFragment.firstChild);
      }
      // -->
    </script>
  </head>
  <body>
    <input type="submit" onclick="test()">
    Output:
  </body>
</html>

和文件的test.xml

<application xmlns="http://ns.adobe.com/air/application/1.0">
  <id>test</id>
  <filename>test</filename>
  <initialWindow>
    <content>test.html</content>
    <visible>true</visible>
  </initialWindow>
</application>

您可以尝试使用调试运行时,例如:

You can try it using the debugging runtime, for example:

adl test.xml

克利克的按钮,它会说:

Klick the button, and it will say:

这篇关于执行XML转换中的Flex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆