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