我用程序处理时,只能出来一部分结果,然后报错,我的工作环境是中文win2000切换到日文字符下面,做出来的东西也是要给日本人用的,不至是不是字符环境的问题,trans.setOutputProperty(OutputKeys.ENCODING," ");里面不知改些什么,反正xsl于xml文件都是EUC-JP的,我的程序很简单如下:
public class Transform {
/**
* Performes an XSLT transformation, sending the results
* to System.out.
*/
public static void main(String[] args) throws Exception {
File xmlFile = new File(xml);
File xsltFile = new File(xsl);
String outputHtml = "output.html";
Source xmlSource = new StreamSource(xmlFile);
Source xsltSource = new StreamSource(xsltFile);
TransformerFactory transFact = TransformerFactory.newInstance();
Transformer trans = transFact.newTransformer(xsltSource);
Result dest = new StreamResult(new File(outputHtml));
// Save the document to the disk file
try
{
TransformerFactory tranFactory = TransformerFactory.newInstance();
DOMSource xslSource = new DOMSource(xslDoc);
Transformer aTransformer = tranFactory.newTransformer(xslSource);
// aTransformer.setOutputProperty(OutputKeys.ENCODING, "UTF8"); // OutputKeys.ENCODING == "encoding"
aTransformer.setOutputProperty("encoding","GB2312");
Source src = new DOMSource(xmlDoc);
Result dest = new StreamResult(new File(outputHtml));
aTransformer.transform(src, dest);
}
catch (TransformerConfigurationException e)
{
e.printStackTrace();
}
catch (TransformerException e)
{
e.printStackTrace();
}
}
// Parses an XML file and returns a DOM document.
// If validating is true, the contents is validated against the DTD
// specified in the file.
public static Document parseXmlFile(String filename, boolean validating)
{
try {
// Create a builder factory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setValidating(validating);
factory.setNamespaceAware(true);
// Create the builder and parse the file
Document doc = factory.newDocumentBuilder().parse(new File(filename));
return doc;
} catch (SAXException e) {
e.printStackTrace();
// A parsing error occurred; the xml input is not valid
} catch (ParserConfigurationException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
}
没错啊,我也是这么些的,不过在显示了一部分结果后就提示下面的错误:
javax.xml.transform.TransformerException: java.lang.NoSuchMethodException
: For extension function, could not find method java.lang.String.eval_conv_for_p
ublication_number_tokkyo_jituyou_bango([ExpressionContext,] #STRING, #NODESET).