本文介绍了在 Java 中使用 Transformer 来实现 XSLT 的多个输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试让我的代码在 xml 文件和 xsl 中调用 - 然后根据 xml 内容执行转换并输出多个结果文件.

I'm currently trying to get my code to call in an xml file and an xsl - then perform the transformation and output multiple outcome files depending on the xml content.

import javax.xml.transform.*;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;

public class TestTransformation {

public static void main(String[] args) throws TransformerException {

System.setProperty("javax.xml.transform.TransformerFactory","net.sf.saxon.TransformerFactoryImpl");
    TransformerFactory tFactory = TransformerFactory.newInstance();

    Source xslt = new StreamSource(new File("transformer.xslt"));

    Transformer transformer = tFactory.newTransformer(xslt);

    Source xmlText = new StreamSource(new File("data.xml"));

    transformer.transform(xmlText, new StreamResult(new File("output.xml")));

但我希望转换生成多个输出文件.. 任何想法将不胜感激!!

But i want the transform to produce multiple output files.. Any ideas would be greatly appreciated!!

推荐答案

您在 XSLT 样式表本身中执行此操作:http://www.w3.org/TR/xslt20/#re​​sult-trees

You do that in the XSLT stylesheet itself: http://www.w3.org/TR/xslt20/#result-trees

这是假设您确实在使用 XSLT 2.0 处理器.在 XSLT 1.0 中,您可以使用 EXSLT 扩展:http://exslt.org/exsl/element/document/index.html - 如果您的处理器支持它.

This is assuming you are indeed using an XSLT 2.0 processor. In XSLT 1.0, you can use an EXSLT extension: http://exslt.org/exsl/elements/document/index.html instead - provided your processor supports it.

这篇关于在 Java 中使用 Transformer 来实现 XSLT 的多个输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 22:55