JSP Version

In this version, the resources listed under the Tools tab of http://www.thexmltoolkit.org are stored in a mySQL database, rather than in an XML file. The JSP script establishes the connection with the database, checks the connection, performs the query, and returns the results to be combined with a static XML file, transformed by the XSL, and formatted with CSS to display the Web page.

The resulting Web page looks exactly like the Tools page on this Web site; the only difference being that the names, descriptions, and URLs of the listed resources come from a database.

* Copyright 2006 Center for Technology in Government.
* The Center grants permission to use and modify this software code free of charge provided  
* this copyright notice is included. By using this code you agree to indemnify the Center from 
* any liability that might arise from its use. Selling the code is expressly forbidden.
* ******************************************************************************************

<%-- Must specify the jsp tag library -- xtags and make sure it has been installed correctly   --%>
<%@ taglib uri="http://jakarta.apache.org/taglibs/xtags-1.0" prefix="xtags" %>

 <%@ page import="java.io.*" %>
 <%@ page import="java.sql.*" %>
   Initial information for database connection and xml translating
String connectionURL = "jdbc:mysql://path_to_database";
String username = "username";
String password = "password";
String tableName = "tablename";
String xmlSource = "path/file.xml";
String xslSource  = "path.file.xsl";
String sqlQuery = "SELECT * FROM  " + tableName;

       Conncect to database and send out the SQL query
Connection connection = null;
Statement statement = null;
ResultSet rs = null;
    connection = DriverManager.getConnection(connectionURL, username, password);
    statement = connection.createStatement();
    rs = statement.executeQuery(sqlQuery);
catch (Exception E) 
	out.println("Unable to load driver. " + E);

 <%-- *********************************************
 * Open XML file, only has title info, no data
 * Get data from database 
 * Convert database data to XML format, 
 * Append new data to XML file, processed only in memory 
 * Generated xml data format must conform to existing XSL sheet
 * Use existing XSL file, nothing needs to be changed
 * New xml data only exist in memory 
**************************************************  --%>
<xtags:parse id="xmlData" uri="<%= xmlSource %>" >
<xtags:context select="//book/chapter">
     while (rs.next()) 
	        <ulink url="<%= rs.getString("url") %>" >
	           <%= rs.getString("title") %>
	       <%= rs.getString("description") +"(" %>
	       <ulink url="<%= rs.getString("url") %>" >
	          <%= rs.getString("url") %>

 * Translate xml data into html 
 * Send back to clent browser
 * Use existing XSL file 
 * Processed in Memory 
***************************************** --%>

 <xtags:style  document="<%= xmlData %>" xsl="<%= xslSource %>">
         <xtags:param name="name" value="<%= tableName %>"/>
         <xtags:param name="extension" value=".jsp"/>

You must have the xtags library installed and configured properly for this script to work. Valid values would need to be inserted for your database connection. Otherwise, this script works much like the scripts in the Environment section of this Web site.