Search code examples
xmlxsltsaxonoxygenxml

How to properly run SQL extensions thru Saxon in Oxygen


I am trying to test usage of the sql extensions of Saxon EE thru Oxygen. I am getting an error that the driver failed to load:

Engine name: Saxon-EE 11.4
Severity: fatal
Problem ID: SXSQ0003
Description: Failed to load JDBC driver org.sqlite.JDBC
Start location: 30:106
URL: http://www.saxonica.com/html/documentation/javadoc/net/sf/saxon/trans/SaxonErrorCode.html#SXSQ0003

This is my XSL:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:sql="http://saxon.sf.net/sql"
    xmlns:saxon="http://saxon.sf.net/"
    exclude-result-prefixes="xs"
    version="3.0">
    
    <xsl:param name="user"/>
    <xsl:param name="password"/>
    
    <xsl:variable name="driver" select="'org.sqlite.JDBC'"/>
    <xsl:variable name="database" select="'jdbc:sqlite:S1000D.db'"/>
    
    <xsl:template match="/">
        <test-output>
            <xsl:apply-templates/>
        </test-output>
    </xsl:template>
    
    <xsl:template match="xref">
        <xsl:variable name="xrefid" select="@xrefid"/>
        <xsl:if test="not(element-available('sql:connect'))">
            <xsl:message terminate="yes">sql:connect not available</xsl:message>
        </xsl:if>
        
        <xsl:message>Connecting to <xsl:value-of select="$database"/>...</xsl:message>
        
        <xsl:variable name="conn" as="java:java.sql.Connection" xmlns:java="http://saxon.sf.net/java-type">
            <sql:connect driver="{$driver}" database="{$database}" user="{$user}" password="{$password}">
                <xsl:fallback>
                    <xsl:message terminate="yes">SQL Extensions are not installed</xsl:message>
                </xsl:fallback>
                <xsl:message>Connected...</xsl:message>
            </sql:connect>
        </xsl:variable>
        
        <xsl:variable name="q">
            <sql:query connection="$conn" table="'DataModule'" column="'*'" where="'LmTask_ID = {$xrefid}'"/>
        </xsl:variable>
        
        <xsl:for-each select="$q">
            <dmRef>
                <dmcode>
                    <!-- Use values from the query to populate the dmcode attributes -->
                </dmcode>
            </dmRef>
        </xsl:for-each>
        
    </xsl:template>
    
</xsl:stylesheet>

This is the SaxonEE config file in our project:

<configuration edition="EE" xmlns="http://saxon.sf.net/ns/configuration" label="Saxon-EE (no threads)">
    <global allowMultiThreading="false" 
        timing="true" 
        validationWarnings="true" 
        validationComments="true" 
        allowExternalFunctions="true" 
        compileWithTracing="false" 
        lineNumbering="true" 
        traceExternalFunctions="true" 
        expandAttributeDefaults="true" 
        allowSyntaxExtensions="true"/>
    <xslt>
        <extensionElement namespace="http://saxon.sf.net/sql" factory="net.sf.saxon.option.sql.SQLElementFactory"/>
    </xslt>
</configuration>

I tried to copy the latest SQLite driver jar (sqlite-jdbc-3.42.0.0.jar) to the Oxygen lib folder and it complained. I them moved it to the lib/connectors folder. It has not complained about it being located there but also still fails. I am not sure where to locate the jar in order for Saxon to load the JDBC.

Any help is much appreciated.


Solution

  • The documentation https://www.oxygenxml.com/doc/versions/25.1/ug-editor/topics/application-reports-errors-on-startup.html suggests, to allow you to add e.g. sqlite-jdbc-3.42.0.0.jar to Oxygen XML's lib folder and to not have it complain, you can put the file in the folder and edit the file libraries.list in there to add e.g. ;sqlite-jdbc-3.42.0.0.jar at the end of the list. I have tested that oXygen then runs Saxon EE 11 successfully doing an sqlite connection with the sql extension elements. Note that while I put the jar in the lib folder and edited the libaries.list I had oXygen closed and then restarted it for the changes to take effect.

    Nevertheless, wait for the oXygen support to tell what they consider the easiest/straight-forward way to have Saxon pick up the sqlite jdbc driver for an XSLT scenario.