我想從XSLT使用sql查詢oracle數據庫;查詢,我正在使用sql9-sql.jar與saxon EE 9.6.0.7版本在哪裏我已經放置ojdc6.jar也在Eclipse的構建路徑。我收到以下錯誤撒克遜轉換導致未知的擴展指令
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)
這裏是我的Java代碼:
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();
}
這裏是我的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>
請讓我知道,如果我失去了某些東西。因爲我在過去3天裏陷入了困境。提前致謝。
我試着將isLicenceFeature設置爲上面提示的,但仍面臨同樣的問題 –
幾乎沒有修改,我可以使用saxon9B版本運行它,但只要我嘗試運行它與薩克森EE我得到上述例外。因爲我需要使用Enterprise Edition來運行它。我已經在eclipse構建路徑下放置了Saxon EE 9.6.0.7和Saxon9-sql,ojdbc6.jar。 @Michael我沒有通過命令提示符運行它,所以我沒有設置類路徑變量。是否需要在我的情況下設置它? –
只是爲了確定,你估計檢查isLicensedFeature()返回true? Eclipse使用自己的機制代表您管理類路徑。我不太瞭解Eclipse,但需要確定的一件事是saxon9-sql在RUNTIME類路徑中:請參閱http://stackoverflow.com/questions/10383226/how-do-i -set-the-runtime-classpath-in-eclipse-4-2 –