1
我想重現Java示例應用程序this例如:使用XSLT。示例應用程序
http://www.w3schools.com/Xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog
這是我的示例應用程序:
input.xml
- 包含在W3Schools的網站transform.xslt
顯示的內容 - 包含顯示在w3schools網站的內容output.xml
- 只是空文件。將被內容填充爲xslt-transformation results
所有文件都在我的/myproject/...resource/myclasspath
目錄中。 [我用getResourceAsStream
])
這,示例應用程序:
public class TestMain {
public static void main(String[] args) throws IOException, URISyntaxException, TransformerException {
TransformerFactory factory = TransformerFactory.newInstance();
InputStream xstlStream = TestMain.class.getResourceAsStream("transform.xslt");
Source xslt = new StreamSource(xstlStream);
Transformer transformer = factory.newTransformer(xslt);
InputStream inputStream = TestMain.class.getResourceAsStream("input.xml");
Source inputSource = new StreamSource(inputStream);
URL url = TestMain.class.getResource("output.xml");
transformer.transform(inputSource, new StreamResult(new File(url.toURI())));
}
}
當我開始這個程序,它仍然不具有output.xml
任何內容。我和w3schools網站上顯示的結果是一樣的例外。
基本上,對於可能特定的情況,我只是想添加屬性到<data></data>
標籤,要有這樣的輸出<data attr=""></data>
。但首先從這個示例應用程序開始。
問:爲什麼它不起作用?
哦..我的上帝。我知道了。每次我在這裏發佈後。我直接在源文件中查找輸出,但沒有編譯。希望這會對某人有所幫助。 – ses 2013-05-11 19:21:01
好的。並在我最後一個問題的答案在這裏:http://stackoverflow.com/questions/2972992/xslt-how-to-add-attributes-to-copy-of – ses 2013-05-11 19:24:58
請添加您的解決方案作爲答案,並接受它,讓人知道這個問題已經回答了。 – JLRishe 2013-05-13 03:19:57