3

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?

1 Answer 1

2

When you run Saxon using the Saxon-EE JAR file but with no license, then (in theory at least) it should behave exactly like Saxon-HE, which means this style of extension function call is not supported.

If you're running from the command line, the -TJ option will give you more detailed diagnostics detailing the search for a matching function.

Sign up to request clarification or add additional context in comments.

1 Comment

When using Saxon-HE, the exception says the HE version doesn't support extension functions (more or less). Without changing any of the code, but just the Saxon library, I get the error above. I'm running it from Eclipse and I've tried setting the -TJ parameter, but the output seems the same.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.