Hi Christian, thanks for your swift reply. I'll get on it right away and I would be interested in that extra parameter :) To dumb this one down a little:
Connect to that database and query for the templates within another
XSL file?
You said:
The current way to do this is transform your request via XQuery and the XSLT module. We may add a parameter for XSLT transformations to our REST API [4]; details would first have to be specified, though.
What would that look like, something like this (in Java)?:
package org.basex.examples.rest;
import java.io.*; import java.net.*;
import org.basex.*;
/** * This class is a simple example to demonstrate applying stored templates from the REST API. * * @author BaseX Mailing list, BSD License */ public final class RESTGet { /** * Runs the example. * @throws IOException I/O exception */ static void run() throws IOException { System.out.println("=== GET: execute a query ===");
// The java URL connection to the resource String base = "http://localhost:8984/rest/";
URL url = new URL(base + "templates?query=(//tag/styleVersion) "); System.out.println("\n* URL: " + url);
// Establish the connection to the URL HttpURLConnection conn = (HttpURLConnection) url.openConnection();
// Print the HTTP response code int code = conn.getResponseCode(); System.out.println("\n* HTTP response: " + code + " (" + conn.getResponseMessage() + ')');
// Check if request was successful if(code == HttpURLConnection.HTTP_OK) { // Print the received result to standard output System.out.println("\n* Result:");
// Get and cache input as UTF-8 encoded stream BufferedReader br = new BufferedReader(new InputStreamReader( conn.getInputStream(), "UTF-8"));
// Print all lines of the result for(String line; (line = br.readLine()) != null;) { System.out.println(line); } br.close(); }
// Close connection conn.disconnect(); }
/** * Main method. * @param args (ignored) command-line arguments * @throws Exception exception */ import javax.xml.transform.*; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; import java.io.File; import java.io.IOException; import java.net.URISyntaxException;
public static void main(final String... args) throws Exception{//, IOException, URISyntaxException, TransformerException { // Start servers final BaseXHTTP http = new BaseXHTTP("-Uadmin", "-Padmin");
TransformerFactory factory = TransformerFactory.newInstance(); // Run example //run();//How does this call the RESTGET class? //for now (You may not want to do make RESTGET instance for every template, instead, it may be easier to ask for a set of templates at once and apply them as a stylesheet here) //For(tags) //Get template and add to stylesheet
Source xslt = theBuiltStyleSheet; Transformer transformer = factory.newTransformer(xslt);
Source text = new StreamSource(new File("input.xml")); transformer.transform(text, new StreamResult(new File("output.xml")));
// Stop servers http.stop(); } }
Best, Simon
The current way to do this is transform your request via XQuery and the XSLT module. We may add a parameter for XSLT transformations to our REST API [4]; details would first have to be specified, though.
Yes, it can also be done in Java. The most compact solution I get in mind is:
1. Create a database X with your XML and XSLT file (called "example" in the following) 2. Go to your browser and visit http://localhost:8984/rest/X/example.xml?query=xslt:transform(.,db:open(.,%2...'))"
If we added an additional xslt parameter, the URL could look as follows:
http://localhost:8984/rest/X/example.xml?xslt=example.xslt
C.
basex-talk@mailman.uni-konstanz.de