[b]问题描述:[/b]
有book.xml如下
[code="java"]
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet href="http://localhost:8082/XMLDemo/book.xsl" type="text/xsl" media="general" ?>
测试手册
这是第一章
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
这是第二章
xxxxxxxxxxxx
xxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
这是第三章
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[/code]
有xsl如下:
[code="java"]
/xsl:template
/xsl:stylesheet
[/code]
然后有类来处理
[code="java"]
public class XSLTFactory extends Action {
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
try{
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html");
PrintWriter out=response.getWriter();
StreamSource content=new StreamSource("http://localhost:8082/XMLDemo/book.xml");
StreamSource style=new StreamSource("http://localhost:8082/XMLDemo/book.xsl");
StreamResult result=new StreamResult(out);
TransformerFactory transformerfactory=TransformerFactory.newInstance();
Transformer transformer=transformerfactory.newTransformer(style);
transformer.transform(content,result);
}catch(Exception e)
{
System.out.println("[ERROR] "+e.toString());
}
return null;
}
}
[/code]
异常信息:
错误:““1”中的语法错误。”
致命错误:“无法编译样式表”
[ERROR] javax.xml.transform.TransformerConfigurationException: 无法编译样式表
czs
哪出问题了?如何解决?
改成就好了,可是浏览器报错了:
无法显示 XML 页。
使用 XSL 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。
XML 文档只能有一个顶层元素。处理资源 'http://localhost:8082/XMLDemo/XSLTFactory.do' 时出错。第 1 行,位置: 95
<?xml version="1.0" encoding="UTF-8"?>
测试手册<...