XALAN register Extension Function like in SAXON

五迷三道 提交于 2019-12-06 13:37:36

问题


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!!


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/3192412/xalan-register-extension-function-like-in-saxon

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!