sql:connect不可用

时间:2016-08-10 11:36:49

标签: java sql xslt saxon

我使用SaxonEE连接xslt和database.i有saxonEE跟踪许可证但是当我运行时结果是sql:connect不可用 这是config.xml文件

<configuration 
    xmlns="http://saxon.sf.net/ns/configuration" 
    edition="EE" 
    licenseFileLocation="saxon-license.lic">
    <xslt> 
        <extensionElement namespace="http://saxon.sf.net/sql" factory="net.sf.saxon.option.sql.SQLElementFactory"/> 
    </xslt>
</configuration>

这是xslt文件

  <xsl:stylesheet 
    xmlns:sql="http://saxon.sf.net/sql"
    version="2.0"
    xmlns:exsl="http://exslt.org/common"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:saxon="http://saxon.sf.net/"
    xmlns:java="http://saxon.sf.net/java-type"
    extension-element-prefixes="saxon sql"

>   
    <xsl:param name="driver" select="'com.mysql.jdbc.Driver'"/> 
    <xsl:param name="database" select="'jdbc:mysql://localhost:3307/Hr'"/> 

    <xsl:template match="/">
        <xsl:if test="not(element-available('sql:connect'))"> 
            <xsl:message>sql:connect is not available</xsl:message> 
        </xsl:if>

        <xsl:variable name="connection"> 
            <sql:connect driver="{$driver}" database="{$database}" user="'root'" password="'root'"></sql:connect> 
        </xsl:variable>
        <xsl:variable name="partner"> 
            <sql:query connection="$connection" table="Partner" column="*" row-tag="Partner" column-tag="col"/> 
        </xsl:variable> 

        <Invoice>
            <Header>
                <InvoiceNumber>123456</InvoiceNumber>
                <InvoiceDate>2016-07-15</InvoiceDate>
            </Header>
            <Partners>
                <partner> 
                    <xsl:copy-of select="$partner"/>
                </partner>
            </Partners>
        </Invoice>  
    </xsl:template>
</xsl:stylesheet> 

这是java代码

            Source configSource = new StreamSource(new File(configPath));
            EnterpriseConfiguration config = new EnterpriseConfiguration();
            config.readConfiguration(configSource);
            EnterpriseTransformerFactory factory = new EnterpriseTransformerFactory(config);

            Source xslt = new StreamSource(new File(inputXSL));
            Transformer transformer = factory.newTransformer(xslt);

            Source text = new StreamSource(new File(dataXML));
            transformer.transform(text, new StreamResult(new File(outputHTML)));

1 个答案:

答案 0 :(得分:0)

最可能的解释是saxon9-sql.jar文件不在你的类路径上。

了解它是如何失败将会有所帮助。