AW: Create Result Set without Iterator
"Eickvonder Bjoern" <[email protected]> Wed, 7 Sep 2005 13:36:01 +0200
| Newsgroups | gmane.text.xml.xindice.user |
|---|---|
| Message-ID | <[email protected]> |
You will probably need to merge the results before transforming. Just create a Document object, create and append a root element of your choice, import and append the result nodes, then transform it. The following should work:
Document doc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
Element root = doc.createElement("result");
doc.appendChild(root);
while (results.hasMoreResources())
{
XMLResource res1 = (XMLResource) results.nextResource();
Node node = res1.getContentAsDOM();
root.appendChild(doc.importNode(node,true));
}
DOMSource src = new DOMSource(doc);
.........
transformer.transform(src, res);
Bjoern Eickvonder
_____
Von: Pasche [mailto:[email protected]]
Gesendet: Mittwoch, 7. September 2005 13:05
An: [email protected]
Betreff: Create Result Set without Iterator
As you can see the Xindice-query returns a result with more than one document. These documents are transformed into a DOMSource Object which is used to transform the documents with an XSLT stylesheet. It was hard for me to get this transformation working. In my example only the last result of the xindice query will be used for the transformation. Is it possible to put all result elements into the src-object? I know that I don´t need the ResourceIterator but I don´t know how to solve the problem without it.
XPathQueryService service = (XPathQueryService) col.getService("XPathQueryService", "1.0");
ResourceSet resultSet = service.query(xpath);
ResourceIterator results = resultSet.getIterator();
while (results.hasMoreResources())
{
/* Element des ResourceIterators in DOMSource umwandeln */
XMLResource res1 = (XMLResource) results.nextResource();
Node node = res1.getContentAsDOM();
DOMSource src = new DOMSource(node);
}
.........
transformer.transform(src, res);
-----
JasDA