在 Java 中为 xsl 创建 ExtensionFunctionDefinition 时 StructuredQName 中的 URI

What Uri in StructuredQName when creating an ExtensionFunctionDefinition in Java for an xsl

我正在尝试在 java 中为 xsl 模板创建撒克逊扩展。我已经将我们经常使用的解决方案中的代码复制粘贴到 'take inspiration'。

当我执行我收到的代码时:

2020-11-17 11:26:45,866 ERROR [stderr] XPST0017 XPath syntax error at char 0 on line 58 near {...($data.pwd...}:
2020-11-17 11:26:45,866 ERROR [stderr]    Cannot find a matching 1-argument function named
2020-11-17 11:26:45,866 ERROR [stderr]       {http://com.aaa.bbb.intializer/xsl/extensions}decrypt-rsa()

我唯一想到的是覆盖方法 getFunctionQName() 中的 uri 的配置。

package it.ccc.bbb.xxx.util;

class XSLDecrypt extends ExtensionFunctionDefinition
{
    private static final String CLASS_NAME = XSLDecryptRSA.class.getName();
    private static final Logger LOGGER = Logger.getLogger(CLASS_NAME);

    @Override
    public StructuredQName getFunctionQName ()
    {
        return new StructuredQName("aaa", "http://com.aaa.bbb.intializer/xsl/extensions", "decrypt");
    }

在构造函数中传递的正确 uri 是什么?

在我的 xsl 中我输入:

<xsl:stylesheet version="2.0" xmlns:aaa="http://com.aaa.bbb.intializer/xsl/extensions">
   ...
   <Parameter Key="password">
       <xsl:value-of select="aaa:decrypt($data.pwd)"/>
   </Parameter>

感谢大家的帮助!

问题的解决方案是在配置中定义新的扩展。在 saxonica's documentation.

中有解释
public class XSLExtensions
{
    private static final ExtensionFunctionDefinition[] xslExtensions;
    
    static
    {
        xslExtensions = new ExtensionFunctionDefinition[] {
                new XSLDecrypt()
        };
    }
    
    public static ExtensionFunctionDefinition[] getExtensions()
    {
        return xslExtensions;
    }
    
    public static void applyTo (net.sf.saxon.Configuration saxonConfig)
    {
        if (xslExtensions != null && xslExtensions.length > 0)
        {
            for(ExtensionFunctionDefinition xslExtension : xslExtensions)
            {
                saxonConfig.registerExtensionFunction(xslExtension);
            }
        }
    }
}

这是在 运行 时应用给定配置的 class,在这种情况下,在我的解决方案中添加了唯一的扩展:XSLDecrypt。

鉴于必须调用 applyTo() 方法(在 运行 时间内),它应该存在一个执行此操作的入口点。不幸的是,我的项目所基于的产品不允许我这样做,所以我们选择了 porkaround。 :( xD

再见!