java - 使用 XSLT。示例应用程序

标签 java xslt

我想重现this Java 示例应用程序中的示例:

http://www.w3schools.com/Xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog

这是我的示例应用程序:

  • input.xml - 包含 w3schools 网站中显示的内容
  • transform.xslt - 包含 w3schools 网站中显示的内容
  • output.xml - 只是空文件。将由内容填充为xslt转换结果

所有文件都位于我的 /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> 。但首先从这个示例应用程序开始。

问:为什么不起作用?

最佳答案

解决方案:只查看已编译的文件夹,但不查看源代码。有包含预期内容的输出文件。

关于java - 使用 XSLT。示例应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16500749/

相关文章:

java - 使用stb_image的stbi_load

xslt - 使用 Xsl :value-of is converting & in url into &amp;

html - xslt 允许在 concat 和 normalize-space 中使用参数

php - 使用应用模板在 XSLT 输出中保留 和其他特殊字符

java - 简单 Intent - jUnit 测试失败

java - 在 ArrayList 中搜索字符串并返回另一个关联的字符串

xslt - 使用XSLT查找文本模式的索引

javascript - 从 javascript 调用 XSLT

java - 有库支持 Guava 表转 csv 格式吗?

java - 对对象数组进行排序会引发 long[] 错误