我希望能夠在AIR項目中使用xslt文件運行xml轉換。什麼是實現這一目標的最佳方式?在Flex中執行XML轉換
2
A
回答
3
在AIR 1.5中,包含支持XSLT的Webkit版本。
從JavaScript中使用類XSLTProcessor
就像在Firefox中一樣。 (注意:有一個令人討厭的bug,Stylesheets不能包含非空格,不管是字面還是字符引用,我被告知更新版本的Webkit將解決這個問題。)
下面是一個完整的例。
創建一個文件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>
,您可以嘗試使用調試運行時,例如:
adl test.xml
KLICK按鈕,它會說:
example http://www.lichteblau.com/tmp/stackoverflow-xslt.png
1
XSLT支持通常由瀏覽器提供。嵌入在AIR中的Webkit版本不支持XSLT。所以,你必須自己做這一切。我發現this項目可讓您在AS3中使用XPath查詢。現在,您必須自己完成模板解析和節點創建。
相關問題
- 1. 用xslt在groovy中執行xml到html轉換
- 2. 在java中執行xml轉換和過濾
- 3. 有沒有辦法在Erlang中執行XML轉換?
- 4. 如何讓特殊的XML字符在flex中未轉換?
- 5. informatica在sql轉換中執行sql
- 6. 的Flex/AIR/AS3 XML換行符問題
- 7. Flex中的狀態轉換
- 8. 在運行時執行隱式轉換
- 9. 在php中轉換XML
- 10. 在Flex中將ByteArray轉換爲Integer
- 11. 在Flex 4.5中將ArrayCollection轉換爲ArrayLIst?
- 12. 將代碼轉換爲Array .....在Flex中
- 13. CheckBox在Flex中被轉換爲Button
- 14. Flex-時區轉換
- 15. Flex狀態轉換
- 16. 在flex中執行撤銷重做
- 17. XML在XML文件轉換
- 18. 無法使Flex轉換行爲順利
- 19. 將XML轉換爲行
- 20. 在XML中將XML轉換爲DATATABLE
- 21. 向下轉換到執行
- 22. XSLT轉換不會執行
- 23. 錯誤執行轉換
- 24. Imagemagick執行並轉換
- 25. 無法執行轉換
- 26. 未執行CSS轉換
- 27. 在Firefox和IE中使用XSLT進行XML到XML轉換
- 28. 轉換XML在Java
- 29. 需要幫助在ASP.NET MVC中執行從XML到HTML的XSL轉換
- 30. Flex:替換XML對象中的節點