AW: XSLT transformation with a xindice result

"Pasche" <[email protected]>
Newsgroups gmane.text.xml.xindice.user
Message-ID <[email protected]>
I cannot believe that it is so hard to convert a XML source into an output
stream :-( I added javax.xml.transform.* but I still get cannot resolve
symbol errors. Do I really need this DOMSource-thing to convert the XML
source which comes from the xindice database with a xslt stylesheet? I`m
even happy if the result of the transformation is listet as an out.println()
in the JSP.

 

Thx Christoph

 

 

<%@ page language="java" %>

<%@ page import="org.xmldb.api.base.*" %>

<%@ page import="org.xmldb.api.modules.*" %>

<%@ page import="org.xmldb.api.*" %>

<%@ page import="org.w3c.dom.*" %>

<%@ page import="javax.xml.transform.dom.*" %>

<%@ page import="javax.xml.transform.stream.*" %>

<%@ page import="javax.xml.transform.*" %>

 

String suche = request.getParameter("suchbegriff");

Collection col = null;

      try {

         String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";

         Class c = Class.forName(driver);

 

         Database database = (Database) c.newInstance();

         DatabaseManager.registerDatabase(database);

 

         col =
DatabaseManager.getCollection("xmldb:xindice://83.137.103.78:8080/db/wikiped
ia");

 

         String xpath = "/output/ART/A0[SSTW='" + suche + "']";

         DOMSource src = null;

         

         XPathQueryService service =

            (XPathQueryService) col.getService("XPathQueryService", "1.0");

         ResourceSet resultSet = service.query(xpath);

         ResourceIterator results = resultSet.getIterator();

         while (results.hasMoreResources()) {

            XMLResource res = (XMLResource) results.nextResource();

            Node node = res.getContentAsDOM();   

            src = new DOMSource(node);         

         }

         

         

         

         // Generate a Transformer.

                                                TransformerFactory factory =
TransformerFactory.newInstance();

                                                

 
javax.xml.transform.Transformer transformer = factory.newTransformer

                  (new javax.xml.transform.stream.StreamSource("pml.xsl"));

                                                                       

                                                // Create an empy DOMResult
object for the output.

 
javax.xml.transform.dom.DOMResult domResult = new
javax.xml.transform.dom.DOMResult();

 

                                                // Perform the
transformation.

                                                transformer.transform(new
javax.xml.transform.dom.DOMSource(src));

 

                                                // Now you can get the
output Node from the DOMResult.

                                                org.w3c.dom.Node output =
domResult.getNode();

                                                StreamResult res = new
StreamResult(output);

 

 
out.println(res.getOutputStream());

      }

      catch (XMLDBException e) {

         System.err.println("XML:DB Exception occurred " + e.errorCode);

      }

      finally {

         if (col != null) {

            col.close();

         }

      }

 

 

 

Generated servlet error:
    [javac] Since fork is true, ignoring compiler setting.
    [javac] Compiling 1 source file
    [javac] Since fork is true, ignoring compiler setting.
    [javac] D:\tomcat\work\Standalone\localhost\weber\ergebnis_jsp.java:140:
cannot resolve symbol
    [javac] symbol  : constructor DOMSource
(javax.xml.transform.dom.DOMSource)
    [javac] location: class javax.xml.transform.dom.DOMSource
    [javac]                            transformer.transform(new
javax.xml.transform.dom.DOMSource(src));
    [javac]                                                        ^
    [javac] D:\tomcat\work\Standalone\localhost\weber\ergebnis_jsp.java:144:
cannot resolve symbol
    [javac] symbol  : constructor StreamResult (org.w3c.dom.Node)
    [javac] location: class javax.xml.transform.stream.StreamResult
    [javac]                            StreamResult res = new
StreamResult(output);
    [javac]                                                     ^
    [javac] 2 errors

 

 

  _____  

Von: Eickvonder Bjoern [mailto:[email protected]] 
Gesendet: Dienstag, 26. Juli 2005 06:24
An: [email protected]
Betreff: AW: XSLT transformation with a xindice result

 

You don't import 'javax.xml.transform.Transformer', try adding <%@ page
import="javax.xml.transform.*" %>.

 

Hope that helps 

 

Björn Eickvonder

 

  _____  

Von: Pasche [mailto:[email protected]] 
Gesendet: Montag, 25. Juli 2005 23:41
An: [email protected]
Betreff: XSLT transformation with a xindice result

I try to transform a XML document  I get from the xindice database. First of
all, I transform the result of the xpath query into a DOMSource. Then I try
to transform this DOMSource with the help of a xslt stylesheet. But I can´t
even compile it (see errors below). I have no idea why I get the “cant
resolve symbol” error. I think I included all classes.

 

 

<%@ page import="org.xmldb.api.base.*" %>

<%@ page import="org.xmldb.api.modules.*" %>

<%@ page import="org.xmldb.api.*" %>

<%@ page import="org.w3c.dom.*" %>

<%@ page import="javax.xml.transform.dom.*" %>

<%@ page import="javax.xml.transform.stream.*" %>

 

String suche = request.getParameter("suchbegriff");

Collection col = null;

      try {

         String driver = "org.apache.xindice.client.xmldb.DatabaseImpl";

         Class c = Class.forName(driver);

 

         Database database = (Database) c.newInstance();

         DatabaseManager.registerDatabase(database);

 

         col =
DatabaseManager.getCollection("xmldb:xindice://83.137.103.78:8080/db/wikiped
ia");

 

         String xpath = "/output/ART/A0[SSTW='" + suche + "']";

         DOMSource src = null;

         

         XPathQueryService service =

            (XPathQueryService) col.getService("XPathQueryService", "1.0");

         ResourceSet resultSet = service.query(xpath);

         ResourceIterator results = resultSet.getIterator();

         while (results.hasMoreResources()) {

            XMLResource res = (XMLResource) results.nextResource();

            Node node = res.getContentAsDOM();   

            src = new DOMSource(node);         

         }

         

         

         

         // Generate a Transformer.

 
javax.xml.transform.Transformer transformer = Factory.newTransformer

                  (new javax.xml.transform.stream.StreamSource("pml.xsl"));

                                                                       

                                                // Create an empy DOMResult
object for the output.

 
javax.xml.transform.dom.DOMResult domResult = new
javax.xml.transform.dom.DOMResult();

 

                                                // Perform the
transformation.

                                                transformer.transform(new
javax.xml.transform.dom.DOMSource(src));

 

                                                // Now you can get the
output Node from the DOMResult.

                                                org.w3c.dom.Node output =
domResult.getNode();

                                                Result res = new
StreamResult(output);

 

 
out.println(res.getOutputStream());

      }

      catch (XMLDBException e) {

         System.err.println("XML:DB Exception occurred " + e.errorCode);

      }

      finally {

         if (col != null) {

            col.close();

         }

      }

 

 

Generated servlet error: 
[javac] Since fork is true, ignoring compiler setting. 
[javac] Compiling 1 source file 
[javac] Since fork is true, ignoring compiler setting. 
[javac] D:\tomcat\work\Standalone\localhost\web\ergebnis_jsp.java:127:
cannot resolve symbol 
[javac] symbol : variable Factory 
[javac] location: class org.apache.jsp.ergebnis_jsp 
[javac] javax.xml.transform.Transformer transformer = Factory.newTransformer

[javac] ^ 
[javac] D:\tomcat\work\Standalone\localhost\web\ergebnis_jsp.java:134:
cannot resolve symbol 
[javac] symbol : constructor DOMSource (javax.xml.transform.dom.DOMSource) 
[javac] location: class javax.xml.transform.dom.DOMSource 
[javac] transformer.transform(new javax.xml.transform.dom.DOMSource(src)); 
[javac] ^ 
[javac] D:\tomcat\work\Standalone\localhost\web\ergebnis_jsp.java:138:
cannot resolve symbol 
[javac] symbol : class ResultSet 
[javac] location: class org.apache.jsp.ergebnis_jsp 
[javac] ResultSet res = new StreamResult(output); 
[javac] ^ 
[javac] D:\tomcat\work\Standalone\localhost\web\ergebnis_jsp.java:138:
cannot resolve symbol 
[javac] symbol : constructor StreamResult (org.w3c.dom.Node) 
[javac] location: class javax.xml.transform.stream.StreamResult 
[javac] ResultSet res = new StreamResult(output); 
[javac] ^ 
[javac] 4 errors



____________
Virus checked by G DATA AntiVirusKit
Version: AVK 15.0.6237 from 25.07.2005
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.