Transformation XSL

Hello!

How can I get data from my tamino database and transform returned data by xsl stylesheet?

any help will be appreciated!

thanks in advance!

best regards,
Dariusz Baumann

PS.
I have been trying in the following way (but it doesn’t work)

Here is my code:
-------------------------------------
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.Transformer;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

import java.io.*;

import com.softwareag.tamino.API.dom.TaminoClient;
import com.softwareag.tamino.API.dom.TaminoError;
import com.softwareag.tamino.API.dom.TaminoResult;

import org.w3c.dom.Element;
import org.w3c.dom.Document;

public class Example2 {

private
TaminoClient tc;
TaminoResult tr;
Document dc;
Element el;

public void main(String arg) {
Example2 example = new Example2();
int pageSize = 0;
String url = “http://localhost/tamino/mydb/col”;
try {
tc = new TaminoClient(url);
tc.setPageSize(pageSize);
tc.startSession();
tr = tc.query(“doc”);
Element el = tr.getElement();
String ls_xsl = “C:\data\doc.xsl”;
StreamSource xsl = new StreamSource(new File(ls_xsl));
TransformerFactory tFactory = TransformerFactory.newInstance();
Transformer transformer = tFactory.newTransformer(xsl);
transformer.transform(el, System.out);
tc.endSession();
}
catch (com.softwareag.tamino.API.dom.TaminoError error) {
System.out.println(error.getMessage());
}
}
}
-------------------------------------

I got the following error text:


Example2.java:39 transform(javax.xml.transform.Source, javax.xml.transform.Result) in javax.xml.transform.Transformer cannot be applied to (org.w3c.dom.Element, java.io.PrintStream)
transformer.transform(el, System.out)
^
1 error


How should I fix my sample code? Please help, thanks a lot!

You won’t be able to use the HTTP client API with JAXP for transformation purposes because JAXP expects DOM level 2 support and the HTTP client API only delivers DOM level 1 objects.

The transform() method takes two parameters which are Source and Result interfaces respectively. You can create a DOMSource element for example using a DOM tree. For the Result you could use StreamResult.


Stuart Fyffe-Collins
Software AG (UK) Ltd.

First of all, thanks for a quick reply, Stuart. :slight_smile:

I still have been trying to get it working but I have got some problems.

However, I found some ideas in the following posts:

1)
http://tamino.forums.softwareag.com/viewtopic.php?p=14489)
http://tamino.forums.softwareag.com/viewtopic.php?p=10948

Finally, now my code like this:

<%@ page
import = “org.w3c.dom.,
javax.xml.transform.
,
com.softwareag.tamino.API.dom2.,
java.util.
,
java.io.*,
javax.xml.transform.stream.StreamSource,
javax.xml.transform.stream.StreamResult”
%>

<%
try {
TaminoClient tc = new TaminoClient(“http://localhost/tamino/mydb/col”);
tc.setPageSize(0);
TaminoResult tr = tc.query(“doc”);
Element el = tr.getElement();
TransformerFactory tFactory = TransformerFactory.newInstance();
String ls_xsl = “C:\data\data.xsl”;
StreamSource xsl = new StreamSource(new File(ls_xsl));
Transformer transformer = tFactory.newTransformer(xsl);
StreamResult result = new StreamResult(out);
transformer.transform(new javax.xml.transform.dom.DOMSource(el), result);
}
catch (Exception e)
{
e.printStackTrace();
}
%>

It is the Example2.jsp page.

Unfortunately, it does NOT transform returned data form tamino. IE shows only plain text (but it should be a pretty table). :frowning:

What is the problem?
Please give some ideas?
How can I fix this code?

in advance, thanks a lot!

best regards,
Dariusz Baumann

Hi Dariusz,

One possible reason that the results are not formatted as expected is that you are not transforming the whole document, but instead only transforming a fragment that the stylesheet processes with the default templates. So maybe change the following line:
transformer.transform(new javax.xml.transform.dom.DOMSource(el), result);

to:
transformer.transform(new javax.xml.transform.dom.DOMSource(el.getOwnerDocument()), result);

Please note that the DomApiClient3.zip is not officially supported; the preferred API to use is the TaminoAPI4J which can be used with JAXP.

Hope this helps,


Stuart Fyffe-Collins
Software AG (UK) Ltd.

yes, now it works. :slight_smile:
table showed in ie. :slight_smile:

thanks Stuart!

However, I made some modification in my code, and I found that previous code can be written in simpler way.


Element el = tr.getElement();
Document d1 = el.getOwnerDocument();


to:

Document d2 = tr.getDocument();


Two lines was changed into one line (code is simpler, of course).

Unfortunately, combination getDocument() and getOwnerDocument() only in Document type is not work. Can you tell me why?


Document d2 = tr.getDocument();
Document d3 = d2.getOwnerDocument();


thanks for help.

best regards,
Dariusz Baumann

PS.
Here is the whole changed code.


<%@ page
import = “org.w3c.dom.,
javax.xml.transform.
,
com.softwareag.tamino.API.dom2.,
java.util.
,
java.io.*,
javax.xml.transform.stream.StreamSource,
javax.xml.transform.stream.StreamResult”
%>

<%
try {
TaminoClient tc = new TaminoClient(“http://localhost/tamino/mydb/col”);
tc.setPageSize(0);
TaminoResult tr = tc.query(“doc”);

Element el = tr.getElement();
Document d1 = el.getOwnerDocument();


Document d2 = tr.getDocument();
Document d3 = d2.getOwnerDocument();

TransformerFactory tFactory = TransformerFactory.newInstance();
String ls_xsl = “C:\data\data.xsl”;
StreamSource xsl = new StreamSource(new File(ls_xsl));
Transformer transformer = tFactory.newTransformer(xsl);
StreamResult result = new StreamResult(out);
// transformer.transform(new javax.xml.transform.dom.DOMSource(d1), result);
// transformer.transform(new javax.xml.transform.dom.DOMSource(d2), result);
transformer.transform(new javax.xml.transform.dom.DOMSource(d3), result);
}
catch (Exception e)
{
e.printStackTrace();
}
%>


I guess this doesn’t work (I’ve not checked it though) because the Document object is the owner document and therefore it doesn’t make sense to ask for the owner document of a document. getOwnerDocument() is really useful to get access to the Document object from any Node object. So your line of:

  
  Document d3 = d2.getOwnerDocument();
</pre><BR><BR>can simply be rewritten to:<BR><BR><pre class="ip-ubbcode-code-pre">
  Document d3 = d2;



Best regards,
Stuart Fyffe-Collins
Software AG (UK) Ltd.