On my tomcat I have a servlet at this address: http://192.168.1.2/FirstApp/TestXslServlet
which generates the following XML:
<?xml version='1.0' encoding='UTF-8'?>
<?xml-stylesheet type="text/xsl" href="./TestBean.xsl"?>
<TheRoot>
<hw>Hello World!</hw>
</TheRoot>
I have the xsl here: http://192.168.1.2/FirstApp/TestBean.xsl
Which contains the following text:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/TheRoot">
<html>
<body>
<h2>XSL loaded!</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th><xsl:value-of select="hw"/></th>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
When I load the servlet all I see is "Hello World!", which is the same I see if I completely remove the xsl or if I put a dummy xsl name, so it appears that there is some problem with loading it. Why?
Both the XML and the XSL should be correct as I tested them on this website: http://markbucayan.appspot.com/xslt/index.html and the transformation went as expected.
EDIT: It appears to be working on explorer, but not on firefox, so the issue is browser-related.
EDIT2: I tried to download both files from firefox to test them locally, the servled downloaded as TestXslServlet.xml
and the xsl downloaded as TestBean.xsl.xml
. I renamed the xsl removing the ".xml" extension and now from the local disk it's working fine.
I tried to see if the firefox developer console could shed any light on what it's happening, if I reload the page on the server I get:
[11:01:39.325] GET http://192.168.1.2/FirstApp/TestXslServlet [HTTP/1.1 200 OK 32ms]
If I reload the page from the local disk I get:
[11:04:00.507] file:///C:/[...]/xsltest/TestBean.xsl
The MIME Type for TestBean.xsl is "application/xml" when loaded from the server and "text/xml" when loaded from the disk.
I tried to upload the exact same files that works on local to the server and they do not work (the difference is that I'm now calling a static TestXslServlet.xml
instead of the servlet to generate the xml, the MIME type is "application/xml", as for the servlet).
EDIT3: In order to rule out any mistake on my part I tried to use the example files provided here: https://developer.mozilla.org/en-US/docs/XSLT_in_Gecko/Basic_Example the page loads fine when loaded from the local disk but the transformation isn't applied when loaded from the server. It appears the be an issue with firefox(v.25) and tomcat(v.7) however the MIME type seems correct to me, from firefox's "page info" it shows "application/xml" for both (when loaded from the server, there is no MIME type information when loaded from local disk).