I'm trying to use the Saxon processor from java. I'm using the the saxon9ee.jar inside saxonee9-3-0-11j.zip (just downloaded, no license - is that needed so it'll work?)
Their ** resources can be found here: http://www.saxonica.com/documentation/extensibility/functions/instance-methods.xml
http://www.saxonica.com/documentation/extensibility/functions/staticmethods.xml
My xsl:
<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:value-of select="dateUtils:getCurrentFullDate()"
xmlns:dateUtils="java:com.macfaq.math.SimpleSaxon"/>
</xsl:template>
</xsl:stylesheet>
My java file:
package com.macfaq.math;
public class SimpleSaxon {
public static final String YMDTHMS = "yyyyMMdd'T'hhmmss";
public static String getCurrentFullDate() {
return (new SimpleDateFormat(YMDTHMS).format(new Date()));
}
}
My input XML file:
<?xml version="1.0" encoding="UTF-8"?>
<date format="yyyyMMdd'T'hhmmss" year="2000" month="4" day="27"/>
My main java file:
public class SaxonTransf {
public static void main(String[] args) {
System.setProperty("javax.xml.transform.TransformerFactory",
"net.sf.saxon.TransformerFactoryImpl");
String foo_xml = "in.xml"; // input xml
String foo_xsl = "transf.xsl"; // input xsl
TransformerFactory tfactory = TransformerFactory.newInstance();
Transformer transformer = tfactory.newTransformer(new StreamSource(
new File(foo_xsl)));
transformer.transform(new StreamSource(new File(foo_xml)),
new StreamResult(System.out));
}
Error: XTDE1425: Cannot find a matching 0-argument function named {java:com.macfaq.math.SimpleSaxon}getCurrentFullDate(). The namespace URI and local name are recognized, but the number of arguments is wrong in built-in template rule.
Has anyone had any luck with calling custom java functions from XSL while using this wonderful processor?