问题
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