【发布时间】:2011-02-02 10:41:38
【问题描述】:
这是一个类似的问题,几乎没有区别:
Split XML file into multiple files based on a threshold value
我的根元素称为stores,要拆分的元素称为store。我想从带有或不带有 xsl 的 java 中执行此操作,这是我用来触发 xsl 的 java 代码:
public void transform(String transformator, File source, String destination) {
try {
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(new StreamSource(transformatorLocation));
try {
transformer.transform(new StreamSource(new InputStreamReader(new FileInputStream(source), "UTF-8")), new StreamResult(new OutputStreamWriter(new FileOutputStream(destination), "UTF-8")));
} catch (TransformerException e) {
e.printStackTrace();
} catch (FileNotFoundException e) {
System.err.println("File is missing");
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
} catch (TransformerConfigurationException e) {
e.printStackTrace();
}
}
我在这个问题上尝试了两种解决方案,但它们都产生错误,一个是:
错误:'不支持的 XSL 元素'http://www.w3.org/1999/XSL/Transform:for-each-group'' javax.xml.transform.TransformerException: java.lang.RuntimeException: 不支持的 XSL 元素 'http://www.w3.org/1999/XSL/Transform:for-each-group'
另外就是样式表无法编译。
我试图完成什么?将参数传递给 java 类,我想要一个文件中有多少个商店,并将其拆分为 n 个部分。
【问题讨论】: