好像这里搞java的都不喜欢说话啊.......
解决方案 »
- 请教BigDecimal的用法,我是初学的
- Java-Excel Poi报空的问题
- jstl显示无效,什么原因?
- html中是否有的basePath?
- cvs [server aborted]: cannot rename file 急急急,坐等。
- 高分提问ExtJs问题,高手请进
- Hibernate多对多关系,中间表有其他字段,如何向其插入数据?
- 在linux下mysql查询时遇到的中文问题,请各位指教
- 我学JSP也有一段时间了..........我应该买那本书来系统学习JAVA??????
- 不用JBoss-Tomcat整合版,该怎么配置两者??
- webstart下运行显示空界面
- 高手 高分请教 (300分) (解决另外开贴给分)
<%@ page contentType="text/html; charset=gb2312" errorPage="systemerror.jsp" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="javax.xml.parsers.*"%>
<%@ page import="java.io.*"%>
<%@ page import="javax.xml.transform.*"%>
<%@ page import="javax.xml.transform.stream.*"%>
<%
StringReader reader=new StringReader(你的xml);
StreamSource xml = new StreamSource(reader);
StreamSource xsl = new StreamSource(xsl文件路径);
StreamResult result = new StreamResult(out); Transformer trans = TransformerFactory.newInstance().newTransformer(xsl); //trans.setOutputProperty(OutputKeys.ENCODING,"GB2312");
trans.setOutputProperty(OutputKeys.METHOD,"html");
trans.setOutputProperty(OutputKeys.VERSION,"4.0");
//trans.setOutputProperty("encoding","UTF-8");
trans.transform(xml, result); %>
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).我看了一下eval_conv_for_publication_number_tokkyo_jituyou_bango其实是XSL脚本中的一个方法名,不知是什么问题?
2.xsl前面的几行改为:
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>二、注意要使用如下语句
// Create a builder factory
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
factory.setNamespaceAware(true);三、转换的源文件为
// Transform.java
import java.io.*;
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
import org.w3c.dom.*;
import org.xml.sax.*;public class Transform
{
public static void main(String[] args)
{
String inputXml = "2375514.xml";
String outputHtml = "2375514.html";
String transXsl = "2.xsl";
Document xmlDoc = parseXmlFile(inputXml, false);
Document xslDoc = parseXmlFile(transXsl, false);
// 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;
}
}四、
输出文件为2375514.html,没有抛出异常;如果不修改2.xsl,将抛出异常五、你可以缩减你自己的代码,增量测试
<?xml version="1.0" encoding="EUC-JP" ?>
<!DOCTYPE stylesheet><xsl:stylesheet version="1.0"
exclude-result-prefixes="msxsl jp local xql"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:jp="http://www.jpo.go.jp"
xmlns:local="#local-functions"
xmlns:xql="#xql-functions"><xsl:include href="gat-com.xsl" />
<xsl:include href="gat-JS-com.xsl" />
<xsl:include href="application-body.xsl" />
<xsl:include href="gat-a-com.xsl" /> <xsl:template match="/">
<html>
<head>我用程序处理时,只能出来一部分结果,然后报错,我的工作环境是中文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));
try{
trans.transform(xmlSource,dest
} catch(Exception e) {
System.out.println(e);
}
}
}