我需要通過XSLT將SVG文件轉換爲HTML5畫布。 問題是關於Javascript。 在SVG文件我有一個腳本標籤有一些代碼,就像在這個簡單的例子:XSLT:如何將Javascript代碼從xml複製到html,修改它的某些行
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="transform.xsl"?>
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
id="slot" width="320" height="245">
<script type="application/javascript"><![CDATA[
var test = 2;
alert("This is a test!");
]]></script>
<----here svg drawing tags--->
</svg>
我要輸出到html在一些地方改進Javascript代碼,並添加一些新的代碼,如下所示:
<html>
<head>
<title> SVG to HTML5!</title>
<script type="application/javascript">
var new_test; <---the new code--->
var test = 4; <---this is the modified code from
alert("This is a new test!"); svg file--->
</script>
</head>
<body>
</body>
</html>
我該怎麼做?
您的示例看起來不太清楚。你想要執行什麼樣的JavaScript代碼修改? – liori
我需要將代碼行更改爲其他...例如: document.getElementById(「x」)。firstChild.nodeValue = x;到 document.getElementById(「x」)。setAttribute('value',x); 因此,如果有辦法解決代碼行並將其改爲我想要的,我就解決了這個問題! – MrMoog
我對XSLT的瞭解比先進的知識少一點,但我認爲這種文本編輯在XSLT中是非常困難的,如果不是不可能的話。當然,我可能是錯的。 – liori