【问题标题】:Calling Java from XSL (SAXON)从 XSL (SAXON) 调用 Java
【发布时间】:2012-03-29 12:37:18
【问题描述】:

我正在尝试使用 java 中的 Saxon 处理器。我正在使用 saxonee9-3-0-11j.zip 中的 saxon9ee.jar(刚刚下载,没有许可证 - 需要这样才能工作吗?)

他们的 ** 资源可以在这里找到: http://www.saxonica.com/documentation/extensibility/functions/instance-methods.xml

http://www.saxonica.com/documentation/extensibility/functions/staticmethods.xml

我的 xsl:

<?xml version="1.0"?>
<xsl:stylesheet 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">

    <xsl:template match="/">  
        <xsl:value-of select="dateUtils:getCurrentFullDate()" 
              xmlns:dateUtils="java:com.macfaq.math.SimpleSaxon"/>
    </xsl:template>

</xsl:stylesheet>

我的 java 文件:

package com.macfaq.math;
public class SimpleSaxon {
public static final String YMDTHMS = "yyyyMMdd'T'hhmmss";
    public static String getCurrentFullDate() {
        return (new SimpleDateFormat(YMDTHMS).format(new Date()));
    }

}

我的输入 XML 文件:

<?xml version="1.0" encoding="UTF-8"?>
<date format="yyyyMMdd'T'hhmmss" year="2000" month="4" day="27"/>

我的主要 java 文件:

public class SaxonTransf {

public static void main(String[] args) {

    System.setProperty("javax.xml.transform.TransformerFactory",
            "net.sf.saxon.TransformerFactoryImpl");
    String foo_xml = "in.xml"; // input xml
    String foo_xsl = "transf.xsl"; // input xsl

    TransformerFactory tfactory = TransformerFactory.newInstance();
    Transformer transformer = tfactory.newTransformer(new StreamSource(
            new File(foo_xsl)));
    transformer.transform(new StreamSource(new File(foo_xml)), 
        new StreamResult(System.out));

}

错误: XTDE1425:找不到匹配的 0 参数函数,名为 {java:com.macfaq.math.SimpleSaxon}getCurrentFullDate()。命名空间 URI 和本地名称 被识别,但内置模板规则中的参数数量错误。

有没有人在使用这个出色的处理器的同时从 XSL 调用自定义 java 函数?

【问题讨论】:

    标签: java xslt stylesheet transformation saxon


    【解决方案1】:

    当您使用 Saxon-EE JAR 文件但没有许可证运行 Saxon 时,那么(至少在理论上)它的行为应该与 Saxon-HE 完全相同,这意味着不支持这种风格的扩展函数调用。

    如果您从命令行运行,-TJ 选项将为您提供更详细的诊断信息,详细说明搜索匹配函数的过程。

    【讨论】:

    • 使用 Saxon-HE 时,异常表示 HE 版本不支持扩展功能(或多或少)。在不更改任何代码的情况下,只更改 Saxon 库,我得到了上面的错误。我从 Eclipse 运行它,我尝试设置 -TJ 参数,但输出似乎相同。
    猜你喜欢
    • 1970-01-01
    • 2021-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-13
    • 2021-10-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多