3 steps
Tuesday, 20 November 2012 · 6 messages · last reply 21 Nov 2012
SK
Simon Knuijver20 Nov 2012 16:15 #
Hi,
I have an xsl or xml file containing xsl templates:
<xsl:template match="compcd" name="tata">
<compcd>
<xsl:value-of
select="string(ns0:LOCATIONSPEC[ns0:ASSETATTRID='VS_TYPE']/ns0:ALNVALUE)
"></xsl:value-of>
</compcd>
</xsl:template>
<xsl:template match="compcd" name="dada">
<equipnum>
<xsl:value-of
select="string(ns0:FXSTAMDATASet/ns0:LOCATIONS/ns0:FXCOMPANYNAME)"></xsl
:value-of>
</equipnum>
</xsl:template>:
Etc
I have a noob question about this, in three quick steps, how do I:
1. Add these templates to a database
2. Put that db in a webservice/server
3. Connect to that database and query for the templates within another XSL file?
Pointers to the proper manual would be fine, thanks!
Best,
Simon
CG
Christian Grün21 Nov 2012 00:54 #
Hi Simon,
Quoted text · Simon Knuijver · 2 lines
> I have a noob question about this, in three quick steps, how do I: > 1. Add these templates to a database
as XSL files are well-formed XML files, you may add them to the database in the same way as you can add XML files. Please consult our documentation for various ways how to do this (e.g. via the GUI, the REST(XQ) APIs, WebDAV, or the Client APIs).
Quoted text · Simon Knuijver · 1 line
> 2. Put that db in a webservice/server
Our Wiki page on web applications may give you the relevant hints.
Quoted text · Simon Knuijver · 2 lines
> 3. Connect to that database and query for the templates within another > XSL file?
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. Would someone out there be interested in such an option?
Christian
[1] http://docs.basex.org/wiki/Main_Page
[2] http://docs.basex.org/wiki/Web_Application
[3] http://docs.basex.org/wiki/XSLT_Module
[4] http://docs.basex.org/wiki/REST#Parameters
SK
Simon Knuijver21 Nov 2012 12:08 #
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:
Quoted text · Christian Grün · 2 lines
>> 3. Connect to that database and query for the templates within another >> XSL file?
You said:
Quoted text · Christian Grün · 1 line
> 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
CG
Christian Grün21 Nov 2012 14:30 #
Quoted text · Simon Knuijver · 1 line
>> 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(.,'example.xslt'))"
If we added an additional xslt parameter, the URL could look as follows:
http://localhost:8984/rest/X/example.xml?xslt=example.xslt
C.
SK
Simon Knuijver21 Nov 2012 14:46 #
Hi Christian,
I see but there you put the entire xslt in one place,
Simon
Quoted text · Christian Grün · 15 lines
-----Original Message----- From: Christian Grün [mailto:christian.gruen at gmail.com] Sent: woensdag 21 november 2012 14:38 To: Simon Knuijver Cc: BaseX Subject: Re: [basex-talk] 3 steps >> 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(.,'example.xslt'))" If we added an additional xslt parameter, the URL could look as follows: http://localhost:8984/rest/X/example.xml?xslt=example.xslt C.
CG
Christian Grün21 Nov 2012 14:53 #
Quoted text · Simon Knuijver · 1 line
> I see but there you put the entire xslt in one place,
I’m not sure what you mean?
Quoted text · Simon Knuijver · 23 lines
> -----Original Message----- > From: Christian Grün [mailto:christian.gruen at gmail.com] > Sent: woensdag 21 november 2012 14:38 > To: Simon Knuijver > Cc: BaseX > Subject: Re: [basex-talk] 3 steps > >>> 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(.,'example.xslt'))" > > If we added an additional xslt parameter, the URL could look as follows: > > http://localhost:8984/rest/X/example.xml?xslt=example.xslt > > C. > >
Written for BaseX 7.3. BaseX may have changed since: please check the current documentation.
⚡Generated with XQuery