You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用Saxon EE与XSLT 2.0遇XPST0017错误:找不到匹配无参new()函数

问题:Saxon EE + XSLT 2.0 转换报错 XPST0017

我正在使用Saxon EE处理器结合XSLT 2.0进行XML到HTML的转换,但XSL文件出现错误。

XSL文件代码

<?xml version="1.0"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:setfile ="java:com.output.extensionFile">

<xsl:param name="outDir" select="setfile:getCurrentDir(setfile:new())"/>
 
</xsl:stylesheet>

Java调用转换器代码

{
    javax.xml.transform.TransformerFactory tFactory = new EnterpriseTransformerFactory();
    XslImportResolver myResolve = new XslImportResolver();
    tFactory.setURIResolver( myResolve );
    javax.xml.transform.Transformer transformer = tFactory.newTransformer
                    (new javax.xml.transform.stream.StreamSource(xslLocation));
    Registry registry = Registry.getRegistry( this );
    transformer.transform( new StreamSource( xmlLocation ),
            new StreamResult( new FileOutputStream( htmlLocation ) ) );
}

Java扩展类代码

public class extensionFile {
  
  // Empty Constructor
public extensionFile()
{
}

   public Object getCurrentDir()
    {
        return ReportStatic.getCurrentDir();
    }

}

错误信息

Static error at char 22 near {...e:getCurrentDir(setfile:new...} in expression in xsl:param/@select on line 78 column 73 :
XPST0017: Cannot find a matching 0-argument function named Q{java:com.output.extensionFile}new(). For diagnostics on
calls to Java methods, use the -TJ command line option or set the Configuration property
FeatureKeys.TRACE_EXTERNAL_FUNCTIONS

中文翻译

在第78行第73列的xsl:param/@select表达式中,字符22附近出现静态错误:
XPST0017: 找不到匹配的0参函数Q{java:com.output.extensionFile}new()。若要排查Java方法调用问题,可使用-TJ命令行选项,或设置Configuration属性FeatureKeys.TRACE_EXTERNAL_FUNCTIONS


解决方案

方案1:修正XSL中Java构造函数调用语法

Saxon调用Java构造函数的正确方式是直接使用类名作为函数,而非new()。修改XSL中的参数表达式:

<xsl:param name="outDir" select="setfile:getCurrentDir(setfile:extensionFile())"/>

方案2:将Java方法改为静态方法(更简便)

把getCurrentDir改为静态方法,无需创建类实例即可直接调用:

  1. 修改Java扩展类:
public class extensionFile {
   public static Object getCurrentDir()
    {
        return ReportStatic.getCurrentDir();
    }
}
  1. 修改XSL中的参数定义:
<xsl:param name="outDir" select="setfile:getCurrentDir()"/>

额外注意事项

  • 确保com.output.extensionFile类已加入Saxon的类路径
  • 若使用方案1,确认类的无参构造函数为公有(当前代码已满足该条件)

内容的提问来源于stack exchange,提问作者ashish sharma

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.12 08:52:15