未找到引用的xsl stylesheet时的默认浏览器xml样式表?

时间:2012-08-10 09:37:24

标签: java xml xslt browser

我希望浏览器找不到样式表时显示原始XML,是否可能?

下面我已经放了我的XML文档的标题。

<?xml version="1.0" encoding="UTF-8" standalone="no"?><?xml-stylesheet type="text/xsl" href="./my_sheet.xsl" title="relativeRef" alternate="YES"?>

当我的服务器上找不到样式表时,我返回404错误,但这会使浏览器的XML解析器停止并显示错误消息。我该怎么办?以下是为样式表提供服务的servlet的JAVA代码。

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp)
        throws ServletException, IOException {      

    edamisUtils.log("Serving my_sheet.xsl");

    //If we could not load my_sheet we throw a 404 error.
    if(my_sheet== null){
        edamisUtils.debug(5, "Did not find the my_sheet.xsl, sending a 404 status response.");
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    //Set the MIME type of the response to text/xsl
    resp.setContentType("text/xsl");
    OutputStream os = resp.getOutputStream();
    os.write(my_sheet.array());

}

谢谢大家,祝你有个美好的一天!

1 个答案:

答案 0 :(得分:0)

您可以返回200和“全部复制”XSL,而不是返回404。

这样的东西
if(my_sheet == null){
   copy the copy_all XSL in the response output stream;
}

可以找到复制所有XSL示例here

相关问题