1

I am trying to query oracle database from XSLT using sql;query, i am using sql9-sql.jar along with saxon EE 9.6.0.7 version where in i have placed ojdc6.jar also in buildpath of eclipse. I am getting below error

queue name is Error in xsl:value-of/@select on line 37 column 65 of pro.xsl: XTDE1450: Unknown extension instruction in built-in template rule ; SystemID: file:/C:/home/oracle/workspace/XSLTsaxonEE/src/com/thbs/viniReq/pro.xsl; Line#: 37 net.sf.saxon.trans.XPathException: Unknown extension instruction at net.sf.saxon.expr.ErrorExpression.evaluateItem(ErrorExpression.java:127) at net.sf.saxon.expr.Expression.process(Expression.java:880) at net.sf.saxon.expr.instruct.DocumentInstr.evaluateItem(DocumentInstr.java:325) at net.sf.saxon.expr.instruct.DocumentInstr.evaluateItem(DocumentInstr.java:50) at net.sf.saxon.expr.Atomizer.evaluateItem(Atomizer.java:317) at net.sf.saxon.expr.Atomizer.evaluateItem(Atomizer.java:37) at net.sf.saxon.expr.AtomicSequenceConverter.evaluateItem(AtomicSequenceConverter.java:311) at net.sf.saxon.expr.AtomicSequenceConverter.evaluateItem(AtomicSequenceConverter.java:34) at net.sf.saxon.expr.instruct.ValueOf.evaluateItem(ValueOf.java:313) at net.sf.saxon.expr.instruct.ValueOf.evaluateItem(ValueOf.java:45) at net.sf.saxon.expr.instruct.SimpleNodeConstructor.iterate(SimpleNodeConstructor.java:281) at net.sf.saxon.expr.instruct.BlockIterator.next(BlockIterator.java:49) at net.sf.saxon.expr.instruct.Message.processLeavingTail(Message.java:214) at net.sf.saxon.expr.instruct.Block.processLeavingTail(Block.java:657) at net.sf.saxon.expr.instruct.TemplateRule.applyLeavingTail(TemplateRule.java:393) at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:456) at net.sf.saxon.trans.TextOnlyCopyRuleSet.process(TextOnlyCopyRuleSet.java:65) at net.sf.saxon.trans.Mode.applyTemplates(Mode.java:433) at net.sf.saxon.Controller.transformDocument(Controller.java:2291) at net.sf.saxon.Controller.transform(Controller.java:1889) at net.sf.saxon.s9api.XsltTransformer.transform(XsltTransformer.java:553) at net.sf.saxon.jaxp.TransformerImpl.transform(TransformerImpl.java:183) at com.thbs.viniReq.TransformXsl.main(TransformXsl.java:90)


Here is my java code:

 public static void main(String[] args) throws XPathException { 

   System.setProperty("javax.xml.transform.TransformerFactory","net.sf.saxon.TransformerFactoryImpl");  

    EnterpriseConfiguration config=new EnterpriseConfiguration();
    config.setExtensionElementNamespace("http://ns.saxonica.com/sql", "net.sf.saxon.option.sql.SQLElementFactory");

    EnterpriseTransformerFactory factory = new EnterpriseTransformerFactory();
    factory.setConfiguration(config);
    try {  
        Transformer transformer =  factory.newTransformer(new StreamSource(new File(xslt)));

         transformer.transform(new StreamSource(new File(xml)),  
                              new StreamResult(new File(resultDir))); 

       transformer.setOutputProperty(OutputKeys.INDENT, "yes");
    } catch (Exception e) {  
        e.printStackTrace();  
    }  

Here is my XSLT:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:sql="http://ns.saxonica.com/sql"
 xmlns:xsd="http://www.w3.org/2001/XMLSchema"
 xmlns:java="http://saxon.sf.net/java-type"
 xmlns:saxon="http://saxon.sf.net/"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 exclude-result-prefixes="java saxon xsd xsi xsl"
 extension-element-prefixes="saxon sql"
 >
<xsl:output indent="yes"/>
<xsl:strip-space elements="*"
/>

<!-- Database Querying -->
<xsl:param name="jdbc.driver"   as="xsd:string" select="'oracle.jdbc.OracleDriver'" />
<xsl:param name="jdbc.database" as="xsd:string" select="'jdbc:oracle:thin:@localhost:1521:orclaq'" />
<xsl:param name="jdbc.user" as="xsd:string" select="'artl'" />
<xsl:param name="jdbc.pass" as="xsd:string" select="'artl'" />

<xsl:template match="OrderSubline">

<xsl:variable name="sql.conn" as="java:java.sql.Connection">
              <sql:connect driver="{$jdbc.driver}" database="{$jdbc.database}" user="{$jdbc.user}" password="{$jdbc.pass}">
                <xsl:fallback>
                  <xsl:message terminate="yes">SQL extenstions are not installed</xsl:message>
                </xsl:fallback>
              </sql:connect>
</xsl:variable>
<xsl:variable name="queue-table">
    <sql:query connection="$sql.conn" table="QUEUE_CONFIG" column="QUEUE_NAME" row-tag="book" column-tag="col" where="QUEUE_NAME='TVXX_INPT'"/>

</xsl:variable>
<xsl:variable name="queue-id">
    <sql:query connection="$sql.conn" table="QUEUE_CONFIG" column="QUEUE_ID" row-tag="book" column-tag="col" where="QUEUE_NAME='TVXX_INPT'"/>
</xsl:variable>
<xsl:message>queue name is <xsl:value-of select="$queue-table"/></xsl:message>

<RequestHeader>
<NeType><xsl:value-of select="$queue-table"/></NeType>
<OrderNo>100001</OrderNo>
<ReqUser>ff</ReqUser>
</RequestHeader>
</xsl:template>

</xsl:stylesheet>

Kindly let me know if i am missing on something. As i am stuck in it from past 3 days. Thanks in advance.

potame
  • 7,597
  • 4
  • 26
  • 33
Gurpreet Singh
  • 53
  • 1
  • 2
  • 9

1 Answers1

0

I can't immediately see what's wrong here, but the first possibility that comes to mind, which should be investigated and eliminated as a possible cause, is that the license file isn't being found. (This would cause Saxon to run essentially in Saxon-HE mode.) Since you've got the Configuration object to hand, the simplest way to check this is

config.isLicensedFeature(Configuration.LicenseFeature.ENTERPRISE_XSLT)

If it does turn out to be a license issue then we need to look at the classpath. I note you are running in Eclipse, and dynamic loading in Eclipse can be fairly quirky.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • I tried placing the isLicenceFeature as suggested above, but still am facing the same issue – Gurpreet Singh Dec 15 '15 at 06:35
  • With few modifications i am able to run it using saxon9B version, but as soon as i try to run it with Saxon EE i am getting the above exception. Where as i am in need to run it with Enterprise Edition. I have placed Saxon EE 9.6.0.7 and Saxon9-sql, ojdbc6.jar all under eclipse buildpath. @Michael I am not running it through command prompt, so i have not set class path variable. Is it required to set it in my case? – Gurpreet Singh Dec 15 '15 at 06:47
  • Just to be certain, you presumably checked that isLicensedFeature() return true? Eclipse manages the classpath on your behalf using its own mechanisms. I don't know Eclipse at all well, but one thing you need to be sure of is that saxon9-sql is on the RUNTIME classpath: see for example http://stackoverflow.com/questions/10383226/how-do-i-set-the-runtime-classpath-in-eclipse-4-2 – Michael Kay Dec 15 '15 at 11:10
  • I am getting isLicenceFeature as false – Gurpreet Singh Dec 15 '15 at 11:40
  • Also i can see saxon9-sql. jar is present in eclipse runtime – Gurpreet Singh Dec 15 '15 at 11:48
  • I have placed the licence file in src folder and am getting isLicenceFeature as true. – Gurpreet Singh Dec 15 '15 at 11:55
  • However, the previous exception is gone, but am getting: – Gurpreet Singh Dec 15 '15 at 11:56
  • java.lang.NoSuchMethodError: net.sf.saxon.expr.Literal.makeEmptySequence()Lnet/sf/saxon/expr/Literal; – Gurpreet Singh Dec 15 '15 at 11:56
  • That failure strongly suggests that you have JAR files on your classpath from several different versions of Saxon: most likely the saxon9-sql JAR file is not from the same Saxon version as the saxon9ee.jar file. – Michael Kay Dec 15 '15 at 12:57
  • thanks for your extended support, Yes it was the case my saxon9-sql jar was from saxon B and i was using Saxon EE jar with it. – Gurpreet Singh Dec 15 '15 at 19:59
  • After replacing the jar with same version, its working as expected. Once again thanks a ton – Gurpreet Singh Dec 15 '15 at 20:00