aspose file tools*
The moose likes Tomcat and the fly likes A strange problem of XSLT transformation in Tomcat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Tomcat
Bookmark "A strange problem of XSLT transformation in Tomcat" Watch "A strange problem of XSLT transformation in Tomcat" New topic
Author

A strange problem of XSLT transformation in Tomcat

Nikko Liang
Greenhorn

Joined: Jan 15, 2005
Posts: 2
Hello all,

I have written a jsp file which is used to identify the user agent (MSIE or Nokia wap browser) and select xml file and corresponding stylesheet to make XSLT transformation. It is done in a Tomcat web server.

I find there are different ways to make the Tomcat work. If I install the zip one, I should commont out the stylesheet declaration in the XML file to make the jsp file work. And if I install the .exe program, I have to commont out both stylesheet and DTD declaration in the XML. Do you know what makes this difference?

Thank you in advance.

Nikko
Nikko Liang
Greenhorn

Joined: Jan 15, 2005
Posts: 2
I mean to make the jsp file work.

It is just a simple transformation. I put a xml file, a jsp file and 2 xsl files (one for MSIE, one for Nokia WAP browser) in the same folder. Then I run Tomcat. If I do not comment out the stylesheet or DTD declaration in the xml, then I use IE to load the jsp file (http://localhost:8080/xxxx/xxxx.jsp), nothing happens. It is the case when I use the .exe program to install tomcat.

If I install the zip file of Tomcat, it is another case. IE will display a Exception, which is:

HTTP Status 500 - type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception javax.servlet.ServletException: The processing instruction target matching "[xX][mM][lL]" is not allowed. org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:846) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:779) org.apache.jsp.presidentialElectionsUS_jsp._jspService(presidentialElectionsUS_jsp.java:114) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) root cause javax.xml.transform.TransformerException: The processing instruction target matching "[xX][mM][lL]" is not allowed. org.apache.xalan.transformer.TransformerImpl.fatalError(TransformerImpl.java:739) org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:715) org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1129) org.apache.xalan.transformer.TransformerImpl.transform(TransformerImpl.java:1107) org.apache.jsp.presidentialElectionsUS_jsp._jspService(presidentialElectionsUS_jsp.java:105) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236) javax.servlet.http.HttpServlet.service(HttpServlet.java:802) note The full stack trace of the root cause is available in the Apache Tomcat/5.0.30 logs.

-------------------------------------------------------------------------------- Apache Tomcat/5.0.30


And here is the code of my jsp:

<%@ page import="javax.xml.parsers.*"%>
<%@ page import="org.w3c.dom.*"%>
<%@ page import="javax.xml.transform.*"%>
<%@ page import="javax.xml.transform.stream.*"%>
<%@ page import="java.io.*"%>
<%
String userAgent = request.getHeader("User-Agent");
String action = request.getParameter("action");
StreamSource xml = null;
StreamSource xsl = null;
if (userAgent.indexOf("Nokia")>=0)
{
// Requesting browser is Nokia Browser
response.setContentType("text/vnd.wap.wml");
xml = new StreamSource(new File("C:\\jakarta-tomcat-5.0.30\\webapps\\s0401889\\presidentialElectionsUS.xml"));
xsl = new StreamSource(new File("C:\\jakarta-tomcat-5.0.30\\webapps\\s0401889\\presidentialElectionsUS_WML.xsl")); }
if (userAgent.indexOf("MSIE")>=0)
{
// We are running Internet Explorer
response.setContentType("text/html");
xml = new StreamSource(new File("C:\\jakarta-tomcat-5.0.30\\webapps\\s0401889\\presidentialElectionsUS.xml"));
xsl = new StreamSource(new File("C:\\jakarta-tomcat-5.0.30\\webapps\\s0401889\\presidentialElectionsUS_HTML.xsl"));
}
// Note linux setup is commented out
/* if (userAgent.indexOf("Nokia")>=0)
{
// Requesting browser is Nokia Browser
response.setContentType("text/vnd.wap.wml");
xml = new StreamSource(new File("/usr/local/javaweb/webapps/s0401889/presidentialElectionsUS.xml"));
xsl = new StreamSource(new File("/usr/local/javaweb/webapps/s0401889/presidentialElectionsUS_WML.xsl"));
}
if (userAgent.indexOf("MSIE")>=0)
{
// We are running Internet Explorer
response.setContentType("text/html");
xml = new StreamSource(new File("/usr/local/javaweb/webapps/s0401889/presidentialElectionsUS.xml"));
xsl = new StreamSource(new File("/usr/local/javaweb/webapps/s0401889/presidentialElectionsUS_HTML.xsl"));
}
*/
StreamResult result = new StreamResult(out);
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(xsl);
transformer.transform(xml, result); %>
[ January 16, 2005: Message edited by: Nikko Liang ]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: A strange problem of XSLT transformation in Tomcat