XALAN 注册扩展函数,就像 SAXON 中一样

发布于 2024-09-09 02:36:20 字数 905 浏览 6 评论 0原文

我想使用 XALAN 通过 XSLT 转换 XML。现在我想使用扩展函数,这个函数必须像SAXON一样添加到JAVA源中:

Method:

TransformerFactory tFactory = TransformerFactory.newInstance();
Configuration c = ((net.sf.saxon.TransformerFactoryImpl) tFactory).getConfiguration();
c.registerExtensionFunction(new FooExtension());

FooExtension:

public class FooExtension extends ExtensionFunctionDefinition {

    private static final long serialVersionUID = -8143237239412146617L;

    @Override
    public SequenceType[] getArgumentTypes() {
        return new SequenceType[] { SequenceType.EMPTY_SEQUENCE };
    }

    @Override
    public StructuredQName getFunctionQName() {
        return new StructuredQName("ns", "http://namespace", "generate-guid");
    }
}

但是它在XALAN (?FunctionTable?, ?FunctionResolver?, ?URIResolver?) 中是如何工作的,我有要通过源代码执行此操作,我不允许在 XSLT 中添加类。

谢谢!!

i want to transform a XML by XSLT with XALAN. Now i want to use a extension-function, this function have to be added in JAVA source like in SAXON:

Method:

TransformerFactory tFactory = TransformerFactory.newInstance();
Configuration c = ((net.sf.saxon.TransformerFactoryImpl) tFactory).getConfiguration();
c.registerExtensionFunction(new FooExtension());

FooExtension:

public class FooExtension extends ExtensionFunctionDefinition {

    private static final long serialVersionUID = -8143237239412146617L;

    @Override
    public SequenceType[] getArgumentTypes() {
        return new SequenceType[] { SequenceType.EMPTY_SEQUENCE };
    }

    @Override
    public StructuredQName getFunctionQName() {
        return new StructuredQName("ns", "http://namespace", "generate-guid");
    }
}

But how does it works in XALAN (?FunctionTable?, ?FunctionResolver?, ?URIResolver?) , i have to do it by source, i'm not allowed to add class in XSLT.

Thanks!!

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

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

发布评论

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

评论(2

清引 2024-09-16 02:36:20

在 Java 代码中注册函数时,您仍然必须在样式表中声明名称空间,不是吗? 之间没有太大的概念差异。

xmlns:ns="http://namespace"

在这种情况下,我认为执行Or

xmlns:ns="xalan://package.classname"

实现只需要包含静态函数,可以在 http://xml.apache.org/xalan-j/extensions.html#ex-java-namespacehttp://www.ibm.com/developerworks/library/x-xalanextensions.html

When registering the function in your java code, you still would have to declare the namespace in your stylesheet, don't you? In that case I don't think there is much conceptual difference between doing

xmlns:ns="http://namespace"

Or

xmlns:ns="xalan://package.classname"

The implementation just needs to contain a static function, further examples can be found at http://xml.apache.org/xalan-j/extensions.html#ex-java-namespace and http://www.ibm.com/developerworks/library/x-xalanextensions.html

我要还你自由 2024-09-16 02:36:20

Xalan 项目中有一些关于此事的优秀文档: http://xml.apache .org/xalan-j/extensions_xsltc.html

There's some excellent documentation on this matter from the Xalan project here: http://xml.apache.org/xalan-j/extensions_xsltc.html

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