I am trying to create a simple test case for an integrated extension function running from the command line.  I have created the followings classes and packaged them into a jar file called interTest.jar.

package net.test;

public class TextExtFuncImpl {

    public static String modStr(String p_Str){
        return "BEGIN-"+p_Str+"-END";
    }

}


package net.test;

import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.lib.ExtensionFunctionCall;
import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.tree.iter.SingletonIterator;
import net.sf.saxon.value.StringValue;

public class TestExtFuncCall extends ExtensionFunctionCall {

    public TestExtFuncCall() {
    }

    @Override
    public SequenceIterator call(SequenceIterator[] sis, XPathContext xpc) throws XPathException {
        String strResult = TextExtFuncImpl.modStr(sis[0].next().getStringValue());
        SequenceIterator retVal = SingletonIterator.makeIterator(new StringValue(strResult));
        return retVal;
    }

}



package net.test;

import net.sf.saxon.lib.ExtensionFunctionCall;
import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.om.StructuredQName;
import net.sf.saxon.value.SequenceType;

public class TestExtFuncDef extends ExtensionFunctionDefinition {

    @Override
    public SequenceType[] getArgumentTypes() {
        return new SequenceType[] {SequenceType.SINGLE_STRING};
    }

    @Override
    public StructuredQName getFunctionQName() {
        return new StructuredQName("", "http://www.test.net/modFuncs", "modStr");
    }

    @Override
    public int getMinimumNumberOfArguments() {
        return 1;
    }

    @Override
    public SequenceType getResultType(SequenceType[] sts) {
        return SequenceType.SINGLE_STRING;
    }

    @Override
    public ExtensionFunctionCall makeCallExpression() {
        return new TestExtFuncCall();
    }

 

}
 


package net.test;

import net.sf.saxon.Configuration;
import net.sf.saxon.Transform;
import net.sf.saxon.trans.CommandLineOptions;
import net.sf.saxon.trans.XPathException;

public class TestTransform extends Transform {

    @Override
    protected void applyLocalOptions(CommandLineOptions options, Configuration config) {
        super.applyLocalOptions(options, config);
        try {
            config.registerExtensionFunction(new TestExtFuncDef());
        } catch (XPathException ex) {
            throw new IllegalArgumentException();
        }

    }

   
}

I use the following source and transformation:

Source file: interTestIn.xml
Contents:

<?xml version="1.0" encoding="windows-1252" ?>
<testroot anattr="Test Attribute Text">
</testroot>

Transformation file: interTest.xsl
 Contents:

<?xml version="1.0" encoding="windows-1252" ?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:inter="http://www.test.net/modFuncs">
  <xsl:output media-type="xml" />
  <xsl:template match="/testroot">
    <xsl:element name="testrootout">
      <xsl:for-each select="@*">
        <xsl:value-of select="inter:modStr(.)" />
      </xsl:for-each>
    </xsl:element>
  </xsl:template>
</xsl:stylesheet>

Here is what I get when I run:

C:\saxonhe9-3-0-5j>java -cp C:\saxonhe9-3-0-5j\interTest.jar;C:\saxonhe9-3-0-5j\
saxon9he.jar net.test.TestTransform -s:C:\saxonhe9-3-0-5j\interTestIn.xml -xsl:C
:\saxonhe9-3-0-5j\interTest.xsl -o:C:\saxonhe9-3-0-5j\interTestOut.xml -TJ
Looking for function {http://www.test.net/modFuncs}modStr
Trying net.sf.saxon.functions.SystemFunctionLibrary
Trying net.sf.saxon.style.StylesheetFunctionLibrary
Trying net.sf.saxon.functions.VendorFunctionLibrary
Trying net.sf.saxon.functions.ConstructorFunctionLibrary
Trying net.sf.saxon.query.XQueryFunctionLibrary
Trying net.sf.saxon.functions.IntegratedFunctionLibrary
Trying net.sf.saxon.style.StylesheetFunctionLibrary
Function {http://www.test.net/modFuncs}modStr not found!
Error at xsl:value-of on line 7 column 50 of interTest.xsl:
  XPST0017 XPath syntax error at char 0 on line 7 in {inter:modStr(.)}:
    Cannot find a matching 1-argument function named {http://www.test.net/modFun
cs}modStr()
Failed to compile stylesheet. 1 error detected.

This seems to be what is called for based on http://saxonica.com/documentation/extensibility/integratedfunctions.xml and what I have found on the Internet.  However, I have not been able to find a complete example like the one I am trying to make (especially the subclass of Transform).

Thank you in advance.