Urgent:Transforming the Tamino Result Set without using Pass

Can anyone tell me how I can output the results of a Tamino query without using the pass thru servlet. Can someone please give me some sample code? I am trying to use the TransformerFactory in the Xalan API but it gives me errors. Can I get some sample code where a tamino resutl set is applied with an xsl stylesheet?
Thanks and Best Regards,
Parth

As described in the reply to your other post, you can insert a URL using the syntax “/theURL” between the _XQL keyword and the “=” of a Tamino query. This causes Tamino to embed an <?xml-stylesheet href="theURL"?> instructuction being embedded into the response document. When interpreted by a browser supporting stylesheets (at least IE) it will retrieve the stylesheet using theURL and transform the result.

Do you want to do the transformation in the client (browser) or in the server?

Why don’t you want to use the PassThru servlet, is it because it uses xt rather than Xalan?

You can write a servlet of your own that does much the same thing as the PassThru servlet, but calls Xalan. If this is what you are trying to do, and it isn’t working, then we would need to see more details of the error messages to determine why it isn’t working.

/
* Title: HospitalServlet + HospitalException
* Description: HospitalServlet + HospitalException is a basic example for retrieving patient files from Tamino
* using Xalan xslt processor
* The patient files are delivered with Tamino
* (In Tamino v3.1.1.4 see x:\Program Files\Software AG\Tamino\Tamino 3.1.1\Help\EXAMPLES\PATIENT
* Note: in this example the url’s are hardcoded and should of course be adapted to your local situation.
* You may want to make them variable.
* taminoBase : http://servername/tamino/ —> mind the last slash
* dataBase: database/collectionname/ —> mind the last slash (better would be to make differentiate between database and collection :wink:
* xsltLocation: Can be any URL that points to a location where your stylesheets are stored also a stylesheet collection in Tamino.
* Here a hardcoded URL is used which points to directory c:\my tamino\bin-div
* I am using following alias in the Apache configuration file: Alias /mytamino “C:/My Tamino/”

* Example of URL to invoke this servlet using Tomcat 3.3: http://localhost/production/hospital?XQL=patient&XSL=default.xsl
* I assume that Tomcat 3.3 is installed in C:\tomcat3.3 —> Change this to your local setting
* production in the URL is the context of the Tomcat Servlet engine it points to: C:\tomcat3.3\webapps\production
* Compile both servlets and copy the classes into directory like: C:\tomcat3.3\webapps\prod\WEB-INF\classes
* Configure your web.xml like this
* <?xml version="1.0" encoding="ISO-8859-1"?>
*
* <!DOCTYPE web-app
* PUBLIC “-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN”
* “http://java.sun.com/j2ee/dtds/web-app_2_2.dtd”>
*
*
*
* hospital
* HospitalServlet
*
*
* hospital
* /hospital/

*
*


* Date: 29 April 2002
* Copyright: PHT + Peter Stamps
* @author PHT + Peter Stamps
* @version 1.1
/

import javax.servlet.http.
;
import java.io.
;
import org.apache.xalan.xslt.;
import java.net.
;


public class HospitalServlet extends HttpServlet implements java.io.Serializable
{
private String xslProcessor = “org.apache.xalan.xslt.XSLTProcessor”;
private org.apache.xerces.parsers.DOMParser parser = null;

public String taminoBase = new String( “http://localhost/tamino/” );
public String dataBase = new String( “xml/hospital/” );

private String xsltLocation = new String(“http://localhost/mytamino/bin-div/”);

private XSLTProcessor processor = null;

public HospitalServlet() { }



public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
log(“in HospitalServlet doGet()”);
this.doPost(req, res);

}

public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException {
log(“in HospitalServlet doPost()”);
long start = System.currentTimeMillis();

res.setContentType(“text/html”);
PrintWriter out = res.getWriter();

// get values from request
String dataBase = req.getParameter(“DB”);
String xql = req.getParameter(“XQL”);
String xslt = req.getParameter(“XSL”);

log( " XQL : " + xql + " XSL: " + xslt );

// start work
try {
if (xql == null)
throw new HospitalException( “TaminoQuery not correct specified, use:
XQL=name”);
if (xslt == null)
throw new HospitalException( “Stylesheet not correct specified, use:
XSL=name”);
// get stylesheet

XSLTInputSource xsltSource = this.getXSLT( xslt );
log("Stylesheet read from url: " + xsltSource );

XSLTInputSource xmlSource = this.taminoQuery( xql );
log("data read from tamino url (xql): " + xmlSource);
XSLTResultTarget outBuffer = new XSLTResultTarget( out );
log("starting stylesheet processing ");
processor.process(xmlSource, xsltSource, outBuffer);
log(“stylesheet processing done”);
} catch ( org.xml.sax.SAXException e ) { log("Stylesheet processing error: " + e);}
catch ( HospitalException e ) { log("Hospital error: " + e);
out.write(e.toHtml() );}
long stop = System.currentTimeMillis();
log("Whole process took ms= " + ( stop -start) );

out.flush();
out.close();


}

private org.apache.xalan.xslt.XSLTInputSource taminoQuery ( String xql ) {

org.apache.xalan.xslt.XSLTInputSource xmlInput = null;

try {
String myURL = new String (taminoBase + dataBase + “?_XQL(1,5)=” + xql);
log("myURL is: " + myURL );

xmlInput = new org.apache.xalan.xslt.XSLTInputSource(myURL);
} catch ( Exception e ) { log("Reading tamino taminoQuery(): "+ e );}
return xmlInput ;
}

private org.apache.xalan.xslt.XSLTInputSource getXSLT ( String xslt ) throws HospitalException {
org.apache.xalan.xslt.XSLTInputSource xslInput = null;

try {
String myURL = new String ( xsltLocation + xslt);
// ping it
URL test = new URL( myURL );
// this check alwaysd result in value -1 when read from tamino!! Peter Stamps
// if ( test.openConnection().getContentLength() == -1 )
// throw new HospitalException( "XSLT Stylesheet not found on server :
" + myURL);

xslInput = new org.apache.xalan.xslt.XSLTInputSource(myURL);

} catch ( Exception e ) {
log("Reading stylesheet getXSLT(): “+ e );
throw new HospitalException( e.toString() );
}
return xslInput ;
}

private void dumpInputStream( InputStream in ,int size){
InputStreamReader reader = new InputStreamReader( in);
char[] buff = new char[size];
int len = 0;
try {
len = reader.read( buff);
log(” Read a data size of : " + new Integer( len).toString());
log( new String( buff) );
} catch ( Exception e ) { log(“dumpInputStream:” + e); }
}



public void init(javax.servlet.ServletConfig conf) throws javax.servlet.ServletException {
super.init( conf );
// read property file and load defined stylesheets
String test = null;
java.util.Enumeration enum = conf.getInitParameterNames();
while ( enum.hasMoreElements() ) {
String name = (String) enum.nextElement();
log("initArg: " + name + " value: " + conf.getInitParameter( name ));

}

test = conf.getInitParameter(“xsltLocation”);
if ( test != null )
xsltLocation = test;
log("set xslt location to: " + test );

test = conf.getInitParameter(“database”);
if ( test != null )
dataBase = test;
log("set database name to: " + test );

test = conf.getInitParameter(“collecTion”);
if ( test != null )
dataBase = test;
log(“set collection name to: " + test );


test = conf.getInitParameter(“taminoBase”);
if ( test != null )
taminoBase = test;
log(“set tamino base url to: " + test );



try {
processor = org.apache.xalan.xslt.XSLTProcessorFactory.getProcessor();
parser = new org.apache.xerces.parsers.DOMParser();
} catch (org.xml.sax.SAXException e ) { System.err.println(“Error loading xalan processor”); }

}

}
==========================
/*
* Title: HospitalServlet + HospitalException
* Description: HospitalServlet + HospitalException is a basic example for retrieving patient files from Tamino
* using Xalan xslt processor
* The patient files are delivered with Tamino
* (In Tamino v3.1.1.4 see x:\Program Files\Software AG\Tamino\Tamino 3.1.1\Help\EXAMPLES\PATIENT
* Date: 29 April 2002
* Copyright: PHT + Peter Stamps
* @author PHT + Peter Stamps
* @version 1.1
*/

public class HospitalException extends Throwable
{

private String errortext = null;
public HospitalException(String err)
{
super();
errortext = err;

}

public String toHtml() {
java.lang.StringBuffer buff = new java.lang.StringBuffer(“

Error generated by Hospital Exception Servlet

”);

buff.append(errortext);

buff.append(””);
return buff.toString();

}
}