XALAN 注册扩展函数,就像 SAXON 中一样
我想使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在 Java 代码中注册函数时,您仍然必须在样式表中声明名称空间,不是吗? 之间没有太大的概念差异。
在这种情况下,我认为执行Or
实现只需要包含静态函数,可以在 http://xml.apache.org/xalan-j/extensions.html#ex-java-namespace 和 http://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
Or
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
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