DBMS_XSLProcessor 是否处理带有扩展名的样式表?

发布于 2024-11-30 07:15:06 字数 3931 浏览 1 评论 0原文

我一直在尝试获取 DBMS_XSLProcessor (仅 pl/sql 包)来转换一个简单的 XSL,该 XSL 具有 java 扩展,按照使用 Oracle 提供的工具处理 XSL 样式表的可接受约定(数据库中的 XSL 处理器包为以及基于 java 的 XML 开发工具包(数据库外部的 XDK)。

这是一个示例 xml 文档 (ceil.xml)(根据 11gR1 数据库的 XSLT 示例中给出的 math.xml 示例稍作修改)

<?xml version="1.0"?>
<doc>
    <n1>2.4</n1>
</doc>

这是我的名为 ceil.xsl 的 XSL:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:mth="http://www.oracle.com/XSL/Transform/java/java.lang.Math"
>
    <xsl:template match="/">
    Should ciel n1 to "3": <xsl:value-of select="mth:ceil(//n1)"/>
    </xsl:template>
</xsl:stylesheet>

这是我的简单 示例pl/sql 匿名块:

DECLARE
    indoc VARCHAR2(2000);
    xsldoc VARCHAR2(2000);
    myParser dbms_xmlparser.Parser;
    indomdoc dbms_xmldom.domdocument;
    xsltdomdoc dbms_xmldom.domdocument;
    xsl dbms_xslprocessor.stylesheet;
    outdomdocf dbms_xmldom.domdocumentfragment;
    outnode dbms_xmldom.domnode;
    proc dbms_xslprocessor.processor;
    buf varchar2(2000);

BEGIN

    indoc := '<?xml version="1.0"?><doc><n1>2.4</n1></doc>';

    dbms_output.put_line( 'Input document [' || indoc || ']' );

    xsldoc :=
        '<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:mth="http://www.oracle.com/XSL/Transform/java/java.lang.Math">
        <xsl:template match="/">
        Should ciel n1 to "3": <xsl:value-of select="mth:ceil(//n1)"/>
        </xsl:template>
        </xsl:stylesheet>';

    dbms_output.put_line( 'before creating new parser:' || systimestamp );
    myParser := dbms_xmlparser.newParser;
    dbms_output.put_line( 'before parsing XML Doc:' || systimestamp );
    dbms_xmlparser.parseBuffer(myParser, indoc);

    indomdoc := dbms_xmlparser.getDocument(myParser);
    dbms_output.put_line( 'before pulling parsed DOM of XML :' || systimestamp );
    dbms_xmldom.writetobuffer(indomdoc, buf);
    dbms_output.put_line(buf);

    dbms_xmlparser.parseBuffer(myParser, xsldoc);
    xsltdomdoc := dbms_xmlparser.getDocument(myParser);
    dbms_output.put_line( 'before pulling parsed DOM of XSL :' || systimestamp );

    xsl := dbms_xslprocessor.newstylesheet(xsltdomdoc, '');
    proc := dbms_xslprocessor.newProcessor;

    --apply stylesheet to DOM document
    dbms_output.put_line( 'before processing XSL:' || systimestamp );
    outdomdocf := dbms_xslprocessor.processxsl(proc, xsl, indomdoc);
    outnode := dbms_xmldom.makenode(outdomdocf);

    dbms_xmldom.writeToBuffer( outnode, buf );
    dbms_output.put_line( 'after writing to output buffer:' || systimestamp );
    dbms_output.put_line( 'Length of output =[' || LENGTH( buf ) || ']' );
    dbms_output.put_line(buf);

END;
/

在 SQL 提示符上运行它会给出以下输出(错误):

Input document [<?xml version="1.0"?><doc><n1>2.4</n1></doc>]
before creating new parser:19-AUG-11 03.32.33.471688000 PM -07:00
before parsing XML Doc:19-AUG-11 03.32.33.472413000 PM -07:00
before pulling parsed DOM of XML :19-AUG-11 03.32.33.476298000 PM -07:00
<?xml version="1.0"?>
<doc>
<n1>2.4</n1>
</doc>

before pulling parsed DOM of XSL :19-AUG-11 03.32.33.490319000 PM -07:00
DECLARE
*
ERROR at line 1:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00607: Invalid reference: 'ceil'.
ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 759
ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 782
ORA-06512: at line 44

但是,当使用 oraxsl 实用程序时,相同的代码可以在 UNIX 提示符上运行...

-->oraxsl ceil.xml ceil.xsl
<?xml version = '1.0' encoding = 'UTF-8'?>

Should ciel n1 to "3": 3
-->

任何想法为什么 java 扩展是只是指内置功能不起作用? 这适用于 Oracle 企业版数据库版本 11.1.0.6。

感谢您的帮助。

I have been trying to get DBMS_XSLProcessor ( the pl/sql package ONLY) to get it to transform a simple XSL which has a java extension as per the acceptable convention for processing XSL stylesheets with Oracle supplied tools (the XSL Processor package within the database as well as the java based XML Developers Kit- XDK outside the database).

Here is a sample xml document (ceil.xml) (slightly modified from the math.xml sample given in the XSLT Examples of the 11gR1 database )

<?xml version="1.0"?>
<doc>
    <n1>2.4</n1>
</doc>

Here is my XSL called ceil.xsl:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:mth="http://www.oracle.com/XSL/Transform/java/java.lang.Math"
>
    <xsl:template match="/">
    Should ciel n1 to "3": <xsl:value-of select="mth:ceil(//n1)"/>
    </xsl:template>
</xsl:stylesheet>

Here is my simple pl/sql anonymous block:

DECLARE
    indoc VARCHAR2(2000);
    xsldoc VARCHAR2(2000);
    myParser dbms_xmlparser.Parser;
    indomdoc dbms_xmldom.domdocument;
    xsltdomdoc dbms_xmldom.domdocument;
    xsl dbms_xslprocessor.stylesheet;
    outdomdocf dbms_xmldom.domdocumentfragment;
    outnode dbms_xmldom.domnode;
    proc dbms_xslprocessor.processor;
    buf varchar2(2000);

BEGIN

    indoc := '<?xml version="1.0"?><doc><n1>2.4</n1></doc>';

    dbms_output.put_line( 'Input document [' || indoc || ']' );

    xsldoc :=
        '<xsl:stylesheet version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:mth="http://www.oracle.com/XSL/Transform/java/java.lang.Math">
        <xsl:template match="/">
        Should ciel n1 to "3": <xsl:value-of select="mth:ceil(//n1)"/>
        </xsl:template>
        </xsl:stylesheet>';

    dbms_output.put_line( 'before creating new parser:' || systimestamp );
    myParser := dbms_xmlparser.newParser;
    dbms_output.put_line( 'before parsing XML Doc:' || systimestamp );
    dbms_xmlparser.parseBuffer(myParser, indoc);

    indomdoc := dbms_xmlparser.getDocument(myParser);
    dbms_output.put_line( 'before pulling parsed DOM of XML :' || systimestamp );
    dbms_xmldom.writetobuffer(indomdoc, buf);
    dbms_output.put_line(buf);

    dbms_xmlparser.parseBuffer(myParser, xsldoc);
    xsltdomdoc := dbms_xmlparser.getDocument(myParser);
    dbms_output.put_line( 'before pulling parsed DOM of XSL :' || systimestamp );

    xsl := dbms_xslprocessor.newstylesheet(xsltdomdoc, '');
    proc := dbms_xslprocessor.newProcessor;

    --apply stylesheet to DOM document
    dbms_output.put_line( 'before processing XSL:' || systimestamp );
    outdomdocf := dbms_xslprocessor.processxsl(proc, xsl, indomdoc);
    outnode := dbms_xmldom.makenode(outdomdocf);

    dbms_xmldom.writeToBuffer( outnode, buf );
    dbms_output.put_line( 'after writing to output buffer:' || systimestamp );
    dbms_output.put_line( 'Length of output =[' || LENGTH( buf ) || ']' );
    dbms_output.put_line(buf);

END;
/

Running this on an SQL Prompt gives me the following output (error):

Input document [<?xml version="1.0"?><doc><n1>2.4</n1></doc>]
before creating new parser:19-AUG-11 03.32.33.471688000 PM -07:00
before parsing XML Doc:19-AUG-11 03.32.33.472413000 PM -07:00
before pulling parsed DOM of XML :19-AUG-11 03.32.33.476298000 PM -07:00
<?xml version="1.0"?>
<doc>
<n1>2.4</n1>
</doc>

before pulling parsed DOM of XSL :19-AUG-11 03.32.33.490319000 PM -07:00
DECLARE
*
ERROR at line 1:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00607: Invalid reference: 'ceil'.
ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 759
ORA-06512: at "XDB.DBMS_XSLPROCESSOR", line 782
ORA-06512: at line 44

However this same code works on the UNIX prompt when using oraxsl utility...

-->oraxsl ceil.xml ceil.xsl
<?xml version = '1.0' encoding = 'UTF-8'?>

Should ciel n1 to "3": 3
-->

Any ideas why the java extension, which is just referring to a built-in function not working?
This is for an Oracle Enterprise Edition Database Release 11.1.0.6.

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹉夏雨初晴づ 2024-12-07 07:15:06

我无法帮助您使用 Oracle XSLT 处理器,但我可以告诉您,从 XSLT 调用 Java 没有标准 - 每个处理器都做自己的事情。

I can't help you with the Oracle XSLT proecssor, but I can tell you that there are no standards for calling Java from XSLT - each processor does its own thing.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文