I have tried upgrading from SaxonCS 11 to 12 after my ExtensionFunctions are no longer called I get the following exception when I try to compile my xslt.
Saxon.Hej.trans.XPathException: 'Cannot find a 2-argument function named Q{urn:rhea/xpath}get-svgid()'
In SaxonCS 11 everthing worked fine. I was not able to find any information regarding this breaking change in the following documentation
My ExtensionFunctionDefinition looks like this.
public class GetSVGID : ExtensionFunctionDefinition
{
public override QName FunctionName => new QName("urn:rhea/xpath", "get-svgid");
public override int MinimumNumberOfArguments => 1;
public override int MaximumNumberOfArguments => 2;
public override XdmSequenceType[] ArgumentTypes =>
new[]
{
new XdmSequenceType(XdmAtomicType.BuiltInAtomicType(QName.XS_STRING), '?'),
new XdmSequenceType(XdmAtomicType.BuiltInAtomicType(QName.XS_STRING), '?')
};
public override XdmSequenceType ResultType(XdmSequenceType[] ArgumentTypes)
{
return new(XdmAtomicType.BuiltInAtomicType(QName.XS_STRING), '?');
}
public override bool TrustResultType => true;
public override ExtensionFunctionCall MakeFunctionCall()
{
return new GetSVGIDCall();
}
}
Is this a known problem. What is required to migrate this code?
using SaxonApi = Saxon.Api;
var spro = new SaxonProcessor();
XsltCompiler compiler = spro.Processor.NewXsltCompiler();
compiler.ErrorReporter = error => spro.ErrorList.Add(error);
spro.Processor.RegisterExtensionFunction(new GetSVGID());
spro.Executable = compiler.Compile(new Uri(xsltRootPath))
Wrapper Class:
public class SaxonProcessor
{
public List<SaxonApi.Error> ErrorList = new();
public SaxonApi.Processor Processor = new SaxonApi.Processor(true);
public DocumentBuilder DocBuilder;
public XsltExecutable Executable;
public bool First;
}
XSLT Part
<xsl:template name="rhea:get-svgid">
<xsl:param name="fname" />
<xsl:param name="fid" />
<xsl:param name="fidraw" />
<xsl:choose>
<xsl:when test="$CBmode = 'CB'">
<xsl:value-of select="ext:get-svgid($DocIndex, $fname)"/>
</xsl:when>
<xsl:otherwise>
<xsl:text>CB:</xsl:text>
<xsl:value-of select="$fid"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:variable name="rheaMediaID">
<xsl:call-template name="rhea:get-svgid">
<xsl:with-param name="fname">
<xsl:value-of select="@boardno | @infoEntityIdent"/>
</xsl:with-param>
<xsl:with-param name="fid">
<xsl:value-of select="$figureID"/>
</xsl:with-param>
<xsl:with-param name="fidraw">
<xsl:value-of select="$figureIDraw"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
I'm not aware of any breaking change in this area, and the unit tests are all running fine, but the devil is always in the detail. The detail in this case is probably about how you are running the query/transformation and how you are registering your extension function. The error message suggests that it's nothing to do with the way the extension function is written, and everything to do with the way it is registered.
You haven't actually said where you are calling the function from (XSLT, XQuery, XPath) and it makes a difference because the function libraries are set up differently in each case.
You're welcome to raise issues like this on the support forum at saxonica.plan.io.