Re: Cannot find extension function using 10.x
Michael Kay <mike-JkSD5nQpfvpWk0Htik3J/[email protected]>
| Newsgroups | gmane.text.xml.saxon.help |
|---|---|
| Message-ID | <[email protected]> |
The code you've shown us is fine, so there's something wrong in the code you haven't shown us...
I ran this JUnit test based on your code, and it worked fine:
public void testIntegratedExtensionFunctionXslt3() {
try {
Processor proc = new Processor(false);
proc.registerExtensionFunction(new ConstructDocument(proc));
XsltCompiler comp = proc.newXsltCompiler();
StringReader sr = new StringReader(
"<xsl:stylesheet version='2.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:f='https://w3id.org/atomgraph/client#' xmlns:xs='http://www.w3.org/2001/XMLSchema'>" +
"<xsl:template name='go'><a name=\"{f:construct-doc(xs:anyURI('http://a/'), xs:anyURI('http://b/'), xs:anyURI('http://c/'))/*/name()}\"/></xsl:template>" +
"</xsl:stylesheet>");
XsltExecutable exec = comp.compile(new StreamSource(sr));
XsltTransformer xsl = exec.load();
xsl.setInitialTemplate(new QName("go"));
StringWriter sw = new StringWriter();
Serializer out = proc.newSerializer();
out.setOutputWriter(sw);
xsl.setDestination(out);
xsl.transform();
assertTrue("out", sw.toString().contains("doc52"));
} catch (Exception e) {
e.printStackTrace();
fail(e.getMessage());
}
}
public static class ConstructDocument implements ExtensionFunction {
private final Processor processor;
public ConstructDocument(Processor processor) {
this.processor = processor;
}
@Override
public QName getName() {
return new QName("https://w3id.org/atomgraph/client#", "construct-doc");
}
@Override
public SequenceType getResultType() {
return SequenceType.makeSequenceType(ItemType.DOCUMENT_NODE,
OccurrenceIndicator.ZERO_OR_MORE);
}
@Override
public SequenceType[] getArgumentTypes() {
return new SequenceType[]
{
SequenceType.makeSequenceType(ItemType.ANY_URI,
OccurrenceIndicator.ONE),
SequenceType.makeSequenceType(ItemType.ANY_URI,
OccurrenceIndicator.ZERO_OR_MORE),
SequenceType.makeSequenceType(ItemType.ANY_URI,
OccurrenceIndicator.ONE),
};
}
@Override
public XdmValue call(XdmValue[] arguments) throws SaxonApiException {
return processor.newDocumentBuilder().build(new StreamSource(new StringReader("<doc52/>")));
}
public Processor getProcessor() {
return processor;
}
}
It could be for example that you have more than one Processor and you've registered the function with the wrong one; or perhaps you only registered it after compiling the stylesheet (without seeing all your code I can't rule out these possibilities).
If you still can't get it to work, please provide a complete repro so we can actually reproduce the problem.
The configuration option Feature.TRACE_EXTERNAL_FUNCTIONS can be useful for diagnostics on this kind of problem.
Michael Kay
Saxonica
> On 7 Aug 2020, at 13:06, Martynas Jusevičius <martynas-tyFqBaoSXPC1Z/[email protected]> wrote:
>
> Hi,
>
> I've been trying to upgrade to Saxon 10.x and had to implement a few
> (simple) extension functions in the process. I've been following this
> guide:
> https://www.saxonica.com/html/documentation/extensibility/integratedfunctions/ext-simple-J.html
>
> However I get this error message when attempting to use one of them:
>
> Error near {...c:forClass, $ldt:base)/rdf:...} at char 0 in
> xsl:apply-templates/@select on line 650 column 135 of layout.xsl:
> XPST0017: Cannot find a 3-argument function named
> Q{https://w3id.org/atomgraph/client#}construct-doc()
>
> I've double-checked the namespaces.
>
> The function is registered on the Processor:
>
> processor.registerExtensionFunction(new ConstructDocument(processor));
>
> The function itself looks like this:
>
> public class ConstructDocument implements ExtensionFunction
> {
>
> private final Processor processor;
>
> public ConstructDocument(Processor processor)
> {
> this.processor = processor;
> }
>
> @Override
> public QName getName()
> {
> return new QName("https://w3id.org/atomgraph/client#", "construct-doc");
> }
>
> @Override
> public SequenceType getResultType()
> {
> return SequenceType.makeSequenceType(ItemType.DOCUMENT_NODE,
> OccurrenceIndicator.ZERO_OR_MORE);
> }
>
> @Override
> public SequenceType[] getArgumentTypes()
> {
> return new SequenceType[]
> {
> SequenceType.makeSequenceType(ItemType.ANY_URI,
> OccurrenceIndicator.ONE),
> SequenceType.makeSequenceType(ItemType.ANY_URI,
> OccurrenceIndicator.ZERO_OR_MORE),
> SequenceType.makeSequenceType(ItemType.ANY_URI,
> OccurrenceIndicator.ONE),
> };
> }
>
> @Override
> public XdmValue call(XdmValue[] arguments) throws SaxonApiException
> {
> ...
> }
>
> public Processor getProcessor()
> {
> return processor;
> }
>
> }
>
> What am I missing here? Thanks.
>
>
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/saxon-help
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[email protected]
https://lists.sourceforge.net/lists/listinfo/saxon-help