Hello Guys,
I´ve been messing around with BaseX for a few days and now I am kind of stuck.
I have a XSL 2.0 Transformation sheet which works perfectly fine for a standalone application using Saxon HE. Now I tried to use the XSLT module of BaseX with Java. Here is my code:
import java.io.IOException;
import org.basex.core.Context; import org.basex.core.cmd.CreateDB; import org.basex.core.cmd.List; import org.basex.core.cmd.XQuery;
public class App { public static void main(String[] args) { try { // initialize timer final long time = System.nanoTime(); // create session final BaseXClient session = new BaseXClient("localhost", 1984, "admin", "admin"); System.out.println(session.execute("info")); // create db context Context ctx = new Context(); // create db new CreateDB("stammdaten", "stammdaten2.xml").execute(ctx); // show all databases System.out.print(new List().execute(ctx)); // xls transformation System.setProperty("javax.xml.transform.TransformerFactory", "net.sf.saxon.TransformerFactoryImpl"); String query = "declare option output:method 'xml';" + " declare option db:chop 'no';" + " let $in := db:open('stammdaten')" + " let $style := doc('template.xsl')" + " return xslt:transform($in, $style)"; String result = new XQuery(query).execute(ctx); System.out.println("Result: " + result); ctx.close(); // close session session.close(); // print time needed final double ms = (System.nanoTime() - time) / 1000000d; System.out.println("\n\n" + ms + " ms"); } catch(final IOException ex) { // print exception ex.printStackTrace(); } } }
I have started the basexhttp.bat in the bin directory and executed the above code. I get the following console output and stack trace:
General Information: Version: 8.4.1 Used Memory: 20405 KB
Global options: ASYNCTIMEOUT: 3600 AUTHMETHOD: Basic CACHERESTXQ: false DBPATH: C:/Program Files (x86)/BaseX/data DEBUG: false GLOBALLOCK: false HOST: localhost HTTPLOCAL: false IGNORECERT: false KEEPALIVE: 600 LANG: English LANGKEYS: false LOG: true LOGMSGMAXLEN: 1000 NONPROXYHOSTS: PARALLEL: 8 PASSWORD: PORT: 1984 PROXYHOST: PROXYPORT: 0 REPOPATH: C:/Program Files (x86)/BaseX/repo RESTPATH: RESTXQPATH: SERVERHOST: SERVERPORT: 1984 STOPPORT: 8985 TIMEOUT: 30 USER: WEBPATH: C:\Program Files (x86)\BaseX\webapp
Local options ADDARCHIVES: true ADDCACHE: false ADDRAW: false ARCHIVENAME: false ATTRINCLUDE: ATTRINDEX: true AUTOFLUSH: true AUTOOPTIMIZE: false BINDINGS: CASESENS: false CATFILE: CHECKSTRINGS: true CHOP: true COMPPLAN: true CREATEFILTER: *.xml CREATEONLY: false CSVPARSER: DEFAULTDB: false DIACRITICS: false DOTCOMPACT: false DOTPLAN: false DTD: false EXPORTER: FORCECREATE: false FTINCLUDE: FTINDEX: false HTMLPARSER: INLINELIMIT: 100 INTPARSE: false JSONPARSER: LANGUAGE: en LSERROR: 0 MAINMEM: false MAXCATS: 100 MAXLEN: 96 MAXSTAT: 30 MIXUPDATES: false PARSER: xml QUERYINFO: false QUERYPATH: RUNQUERY: true RUNS: 1 SERIALIZE: true SERIALIZER: SKIPCORRUPT: false SPLITSIZE: 0 STEMMING: false STOPWORDS: STRIPNS: false TAILCALLS: 256 TEXTINCLUDE: TEXTINDEX: true TEXTPARSER: TOKENINCLUDE: TOKENINDEX: false UPDINDEX: false WRITEBACK: false XINCLUDE: true XMLPLAN: false
Name Resources Size Input Path ----------------------------------------------------------------------------------------------------------------------------- stammdaten 1 812176 D:/Projekte/XYZ/workspaces/workspace_poc/BaseX/stammdaten2.xml
1 database(s). org.basex.core.BaseXException: Stopped at ., 1/154: [FODC0002] "" (Line 1): Vorzeitiges Dateiende. at org.basex.core.Command.execute(Command.java:101) at org.basex.core.Command.execute(Command.java:123) at net.atos.epi.XMLTransformationProofOfConceptBaseX.App.main(App.java:31) Caused by: org.basex.query.QueryException: "" (Line 1): Vorzeitiges Dateiende. at org.basex.query.QueryError.get(QueryError.java:1344) at org.basex.query.func.xslt.XsltTransform.item(XsltTransform.java:39) at org.basex.query.expr.ParseExpr.iter(ParseExpr.java:44) at org.basex.query.MainModule.iter(MainModule.java:110) at org.basex.query.QueryContext.iter(QueryContext.java:342) at org.basex.query.QueryProcessor.iter(QueryProcessor.java:81) at org.basex.core.cmd.AQuery.query(AQuery.java:90) at org.basex.core.cmd.XQuery.run(XQuery.java:22) at org.basex.core.Command.run(Command.java:398) at org.basex.core.Command.execute(Command.java:100) ... 2 more Caused by: java.io.IOException: "" (Line 1): Vorzeitiges Dateiende. at org.basex.build.xml.SAXWrapper.parse(SAXWrapper.java:83) at org.basex.build.SingleParser.parse(SingleParser.java:33) at org.basex.build.Builder.parse(Builder.java:73) at org.basex.build.MemBuilder.dataClip(MemBuilder.java:77) at org.basex.build.MemBuilder.build(MemBuilder.java:66) at org.basex.build.MemBuilder.build(MemBuilder.java:61) at org.basex.build.MemBuilder.build(MemBuilder.java:50) at org.basex.build.MemBuilder.build(MemBuilder.java:40) at org.basex.query.value.node.DBNode.<init>(DBNode.java:85) at org.basex.query.func.xslt.XsltTransform.item(XsltTransform.java:37) ... 10 more Caused by: org.xml.sax.SAXParseException; systemId: file:///D:/Projekte/XYZ/workspaces/workspace_poc/BaseX/; lineNumber: 1; columnNumber: 1; Vorzeitiges Dateiende. at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.createSAXParseException(Unknown Source) at com.sun.org.apache.xerces.internal.util.ErrorHandlerWrapper.fatalError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLErrorReporter.reportError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLScanner.reportFatalError(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl$PrologDriver.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(Unknown Source) at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source) at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source) at org.basex.build.xml.SAXWrapper.parse(SAXWrapper.java:78) ... 19 more
(Vorzeitiges Dateiende = Premature end of file)
When I run my standalone application with stammdaten2.xml and my template.xsl everything is fine, so I doubt that the stylesheet is the problem. The stylesheet is rather complex and consists of several subtemplates, which are included with <xsl: include href="xyz.xsl" />.
Running the XQuery in the BaseX GUI does not work, since the GUI only provides support for XLST 1.0. Is there a way to change that?
The stacktrace tells me that the system tries to open and parse an empty file, but I have no idea why and which file causes the problem. My assumption is the template.xsl causes the problem, since it said that it "Stopped at ." I copied the stylesheets in every folder that was reasonable for me, but I still got this error. Please tell me what I did wrong.
Best regards, Jan Taschner