The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

chrismech (3) [Avatar] Offline
#1
Hello,

I have thoroughly enjoyed "Ajax in Action" and found practical use for my existing application for the live search example in chapter 12. The only problem is I am pretty new to XSLT and XML, and have run into a problem. I am using IE for my application, but every time I run it I get the following javascript error:
The stylesheet does not contain a document element.
The stylesheet may be empty, or may not be well formed.

Here is the my xsl file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlnssmiliesl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<table id="table1">
<tr>
<th align="left">First Name</th>
<th align="left">Last Name</th>
<th align="left">City</th>
<th align="left">State</th>
<th align="left">DEA</th>
</tr>
<xsl:for-each select="physicianList/physician">
<tr>
<td><xsl:value-of select="firstName"/></td>
<td><xsl:value-of select="lastName"/></td>
<td><xsl:value-of select="city"/></td>
<td><xsl:value-of select="state"/></td>
<td><xsl:value-of select="dea"/></td>
</tr>
</xsl:for-each>
</table>
</xsl:template>
</xsl:stylesheet>

As well as a snippet of my Java server-side code that creates the xml:

ArrayList physicianList = (ArrayList) genericDTO.data;

StringBuffer sb = new StringBuffer();
sb.append("<?xml version='1.0' encoding='utf-8'?>");
sb.append("<physicianList>");

if (physicianList.size() > 0)
{
Iterator physicianIT = physicianList.iterator();

while(physicianIT.hasNext())
{
Physician tempPhysician = (Physician) physicianIT.next();

sb.append("<physician>");
sb.append("<firstName>" + tempPhysician.getFirstName() + "</firstName>");
sb.append("<lastName>" + tempPhysician.getLastName() + "</lastName>");
sb.append("<city>" + tempPhysician.getCity() + "</city>");
sb.append("<state>" + tempPhysician.getState() + "</state>");
sb.append("<dea>" + tempPhysician.getPhysicianDEA() + "</dea>");
sb.append("</physician>");
}
}
else
{
sb.append("<physician>");
sb.append("<firstName>No Results</firstName>");
sb.append("<lastName>N/A</lastName>");
sb.append("<city>N/A</city>");
sb.append("<state>N/A</state>");
sb.append("<dea>N/A</dea>");
sb.append("</physician>");
}

response.setContentType("text/xml");
response.setHeader("Cache-Control", "no-cache");
response.getWriter().write(sb.toString() + "</physicianList>");

Any thoughts, thanks in advance.

Chris Cornelius
Pascarello (208) [Avatar] Offline
#2
Re: XSLT and XML Help
See if the viewing the XML document directly gives you an error: http://radio.javaranch.com/pascarello/2006/09/12/1158096122600.html

Eric
chrismech (3) [Avatar] Offline
#3
Re: XSLT and XML Help
Thanks Eric.

I have found that the dynamic xml is fine by running it in IE. The problem now seems to be the xsl file. For some reason it is not being set in the onXSLLoad function. It has "
" in it, does that matter?
Without Firebug debugging this would have been alot harder. Does anyone know of a good xml editor?

Chris

Message was edited by:
chrismech
chrismech (3) [Avatar] Offline
#4
Re: XSLT and XML Help
After further debugging sessions using Firebug, I noticed that the content-type for the xsl file was set to "text/plain" so I ran the file through my server code and set the response to "text/xml" and now it seems to be working.

Thanks again for the tips,

Chris