Newbie needs help with XSL problems!

Need technical advice on coding your web pages? Covers HTML, JavaScript, CSS, and some server side technologies. Also the issue of some webpages not displayed well.

Moderator: Don_HH2K

Newbie needs help with XSL problems!

Postby AndrewWav » Tue 18 Mar, 2003 9:45 pm

Hello to everyone here and thanks for taking time to read my question! I'm having trouble with a project at school and hoped somebody here might have a solution. This particular XSL page will not properly display in Netscape 7.02, although it is fine in IE. The other XSL page works fine in both. The code follows:

<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl"
xmlns="http://www.w3.org/TR/REC-html40" result-ns="">
<xsl:template match="/">
<html>
<head>
<title>Book Nook Search Results</title>
<link rel='stylesheet' type='text/css' href='http://localhost:8080/BookNook/BookNook.css' />
<style type="text/css">

body {
scrollbar-face-color: green; scrollbar-highlight-color: #ffffff; scrollbar-shadow-color: #ffffff; scrollbar-3dlight-color: #ffffff; scrollbar-arrow-color: #ffffff; scrollbar-track-color: blue; scrollbar-darkshadow-color: #ffffff
}

</style>
<script type="text/javascript" language="JavaScript">
defaultStatus = 'Search Results' ;
</script>
</head>
<body background='http://localhost:8080/BookNook/tn_license_MO.jpg' bgproperties='fixed'>
<div align='center'>
<img src="http://localhost:8080/BookNook/BookNookLogo-large.gif" />
<br /><br /></div>
<div class='title'>The following book(s) match your search criteria:
</div>

<div class='center'>
<br />
<br />
<table border='1' cellpadding='2' cellspacing='2' bordercolor='rgb(0, 164, 101)' bgcolor='rgb(240, 240, 240)'>
<tr class="Headings">
<td align="center" ><b>Book Title</b>
</td>
<td align="center" ><b>Author(s)</b>
</td>
<td align="center" ><b>ISBN #</b>
</td>
<td align="center" ><b>Price per copy</b>
</td>
<td align="center" ><b>Available now?</b>
</td>
<td align="center" ><b>Purchase here</b>
</td>
<td align="center" ><b>Book Reviews</b>
</td>
</tr>
<xsl:apply-templates select="//Product" />
</table>
</div>
<p />
<div align="center">
<input type="button" value="Start Over" onClick="location.href='http://localhost:8080/BookNook/BookNookProductSearch.html' " />
<form method="get" action="http://localhost:8080/BookNook/servlet/ShoppingCart">
<input type="submit" value="View Cart" />
<input type="hidden" name="CartOperation" value="display" />
</form>

</div>
</body>
</html>
</xsl:template>
<xsl:template match="Product">
<tr>
<td><xsl:value-of select="Title" /></td>
<td><xsl:value-of select="Author" /></td>
<td><xsl:value-of select="ISBN" /></td>
<td><xsl:value-of select="Cost" /></td>
<td align="center" ><xsl:value-of select="InStock" /></td>
<td align="center" >
<form method="get" action="http://localhost:8080/BookNook/servlet/ShoppingCart">
<input type="text" name="quantity" value="1" size="1" maxlength='3' />
<input type="hidden" name="CartOperation" value="add" />
<input type="submit" value="Add to cart" />
<input type="hidden" name="ISBN">
<xsl:attribute name="value">
<xsl:value-of select="ISBN" />
</xsl:attribute>
</input>
</form>
</td>
<td align="center">
<form method="get" action="http://localhost:8080/BookNook/servlet/SeeReview">
<input type="submit" value="Read Reviews" />
<input type="hidden" name="ISBN">
</input>
</form>
<form method="get" action="http://localhost:8080/BookNook/servlet/AddReview">
<input type="submit" value="Add Your Review" />
<input type="hidden" name="ISBN">
</input>
</form>
</td>
</tr>
</xsl:template>
</xsl:stylesheet>

This simply displays as text, no background, no images, no buttons, no nothin'. Thanks for any advice! :)
UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; H010818; T312461)
AndrewWav
new member
new member
 
Posts: 4
Joined: Tue 18 Mar, 2003 9:35 pm

Postby Shark Daddy » Tue 18 Mar, 2003 11:13 pm

I'm not familiar with how Mozilla handles XSL, and am fairly new to XSL in the first place. To me it seems good. I suggest you take this question to MozillaZine and ask the same question in the General Forum. Chances are you'd get a good answer.
UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4a) Gecko/20030318
Shark Daddy
Moderator
Moderator
 
Posts: 519
Joined: Wed 19 Jun, 2002 11:19 am
Location: Toronto, Canada

Postby Shark Daddy » Wed 19 Mar, 2003 12:02 am

Try this as your header:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4a) Gecko/20030318
Shark Daddy
Moderator
Moderator
 
Posts: 519
Joined: Wed 19 Jun, 2002 11:19 am
Location: Toronto, Canada

Postby AndrewWav » Wed 19 Mar, 2003 8:15 am

Shark Daddy wrote:I'm not familiar with how Mozilla handles XSL, and am fairly new to XSL in the first place. To me it seems good. I suggest you take this question to MozillaZine and ask the same question in the General Forum. Chances are you'd get a good answer.


Thanks Shark Daddy! I've just done so. :)
UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; H010818; T312461)
AndrewWav
new member
new member
 
Posts: 4
Joined: Tue 18 Mar, 2003 9:35 pm

Postby AndrewWav » Wed 19 Mar, 2003 8:18 am

Shark Daddy wrote:Try this as your header:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


Same result. :sadr: This has really got me bugged now!
UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; H010818; T312461)
AndrewWav
new member
new member
 
Posts: 4
Joined: Tue 18 Mar, 2003 9:35 pm

Postby Shark Daddy » Wed 19 Mar, 2003 7:34 pm

Oi! I'm sorry to see the people at MZ couldn't find an fix/answer straight-up for you. :( Maybe Mr. Zbarsky's suggestion may be the only way...
UserAgent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.4a) Gecko/20030318
Shark Daddy
Moderator
Moderator
 
Posts: 519
Joined: Wed 19 Jun, 2002 11:19 am
Location: Toronto, Canada

Postby AndrewWav » Wed 19 Mar, 2003 7:59 pm

Shark Daddy wrote:Oi! I'm sorry to see the people at MZ couldn't find an fix/answer straight-up for you. :( Maybe Mr. Zbarsky's suggestion may be the only way...


Thanks for all your help on this sticky problem! The only other suspect I can think of is the servlet, and its code is listed below:


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;

public class ProductLookup extends HttpServlet
{
private static void loadJDBCDriver ()
{
System.out.println("");
System.out.println("Product Lookup begins here");
System.out.println ("Loading database driver...");
try
{
DriverManager.registerDriver ( new oracle.jdbc.driver.OracleDriver());
System.out.println ("Database driver loaded...");
}
catch (SQLException e)
{
System.err.println (e.getMessage () + e.toString() );
}
}

private static Connection getConnected ()
{
System.out.println ("getting connection...");
try
{
String jdbc_url = "jdbc:oracle:thin:@localhost:1521:oracle";
Connection conn = DriverManager.getConnection (jdbc_url, "ac", "ac");
System.out.println ("connection created ...");
return conn;
}
catch (SQLException e)
{
System.err.println (e.getMessage () + e.toString() );
}
return null; // never happen
}

private static Statement makeStatement (Connection conn)
{
try
{
System.out.println ("Making a Statement...");
Statement stmt = conn.createStatement ();
System.out.println ("Statement created...");
return stmt;
}
catch (SQLException e)
{
System.err.println (e.getMessage () + e.toString() );
}
return null; // never happen
}

private static ResultSet openResultSet (Statement stmt, String query)
{
try
{
System.out.println ("Creating resultSet...");
ResultSet rs = stmt.executeQuery (query);
System.out.println ("Resultset created...");
return rs;
}
catch (SQLException e)
{
System.err.println (e.getMessage () + e.toString() );
}
return null; // never happen
}

private static void processResultSet (ServletOutputStream out, ResultSet rs)
{
try
{
System.out.println ("\n\n+++++ Processing ResultSet +++++\n");
while (rs.next() )
{
String Cost = null;
Cost = rs.getString("icost");
out.println ("<Product>");
out.println ("<Title>" + rs.getString(1) + "</Title>");
out.println ("<Author>" + rs.getString(2) + "</Author>");
out.println ("<ISBN>" + rs.getString(3) + "</ISBN>");
out.println ("<Cost>" + "$US" + rs.getString(4) + "</Cost>");
if (rs.getInt (5) > 0)
out.println ("<InStock>Yes</InStock>");
else
out.println ("<InStock>No</InStock>");
out.println ("</Product>");
}
System.out.println ("\n\n+++++ ResultSet Processed +++++\n");
}
catch (IOException e)
{
System.err.println (e.getMessage () + e.toString() );
}
catch (SQLException e)
{
System.err.println (e.getMessage () + e.toString() );
}
}

private static void closeThingsDown (ResultSet rs, Statement stmt, Connection conn)
{
try
{
System.out.println ("Closing Things Down...");
rs.close();
System.out.println ("ResultSet Closed...");
stmt.close ();
System.out.println ("Statement closed...");
conn.close();
System.out.println ("Connection closed...");
System.out.println("Product Lookup completed");
System.out.println("");
}
catch (SQLException e)
{
System.err.println (e.getMessage () + e.toString() );
}
}

public void doGet (HttpServletRequest request, HttpServletResponse response)
{
try
{
loadJDBCDriver ();
Connection conn = getConnected ();
Statement stmt = makeStatement (conn);

response.setContentType ("text/xml");
ServletOutputStream out = response.getOutputStream();
out.println ("<?xml version="1.0" standalone="yes"?>"); // xml header
out.println ("<?xml-stylesheet type="text/xsl" href="/BookNook/ProductList.xsl"?>"); // xsl ss

out.println ("<ProductList>"); // root element

// Prepare query based on uploaded user search criteria
String title = request.getParameter ("title");
String author = request.getParameter ("author");
String isbn=request.getParameter("isbn");
String query = "SELECT Title, Author, ISBN, to_char(Cost, '9,990.99') as icost, QuantityOnHand FROM Products ";

if ( title != null & ! title.equals ("") )
query = query + "WHERE Title LIKE '" + title.trim() + "' ";
if (author != null & ! author.equals ("") )
if (query.indexOf ("WHERE") == -1 )
query = query + "WHERE Author LIKE '" + author.trim() + "' ";
else
query = query + "OR Author LIKE '" + author.trim() + "' ";

if (isbn != null & ! isbn.equals("") )
{
if (query.indexOf("WHERE") == -1)
{
query = query+"WHERE isbn LIKE '"+ isbn.trim() + "' ";
}
else
{
query = query + "OR isbn LIKE '"+ isbn.trim()+"' ";
}
}

ResultSet rs = openResultSet (stmt, query);
processResultSet (out, rs); // print results as xml
closeThingsDown (rs, stmt, conn); // close db stuff

out.println ("</ProductList>"); // close root
}
catch (IOException e)
{
System.err.println (e.getMessage () + e.toString() );
}
}

public void doPost (HttpServletRequest request, HttpServletResponse response) {
doGet (request, response);
}
}
UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.0; H010818; T312461)
AndrewWav
new member
new member
 
Posts: 4
Joined: Tue 18 Mar, 2003 9:35 pm


Return to Web Design and Page Coding

Who is online

Registered users: Google [Bot]