1
votes

I am switching from Saxon 9.3 (PE) to more recent version. I am using Extension functions (with "extends ExtensionFunctionDefinition")

I have arguments defined as

public SequenceType[] getArgumentTypes() {                  
        return new SequenceType[] {SequenceType.ANY_SEQUENCE, SequenceType.ANY_SEQUENCE, SequenceType.NODE_SEQUENCE, SequenceType.SINGLE_STRING};

    }

And in the XSLt, the call is made using for exemple a variable on the first argument, which is a built up XML section.

<xsl:variable name="graphXML">
                     <CHART>
                           <xsl:attribute name="FORMAT">PNG</xsl:attribute>
                           <xsl:attribute name="HEIGHT">
...
</xsl:variable>

Upon call,

 private static class GrapheurCall extends ExtensionFunctionCall {

            private static final long serialVersionUID = 1L;

            @Override
             public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {

I needed to change my code because the ExtensionFunctionCall interface changed (previously, I had

 public SequenceIterator call(SequenceIterator[] arguments, XPathContext context) throws XPathException { ...

)

I have two problems now:

1) The parameter type changed from SequenceIterator to Sequence. As such

NodeInfo dataNode = (NodeInfo) arguments[0].next();

could no more be used, and

NodeInfo dataNode = (NodeInfo) arguments[0];

gives me a runtime error

net.sf.saxon.value.SingletonItem cannot be cast to net.sf.saxon.om.NodeInfo

though the object received is a TinyTree (as per debug done at runtime).

2) The return value is also different (from SequenceIterator to Sequence) I had previously return new ListIterator(saxon_result);

Which is not possible anymore (saxon_result being a java.util.ArrayList ) And here, i have no idea how to send back my ArrayList as a sequence...

Can any knowledgeable people shed some light on this? Thanks! Fabien

1

1 Answers

1
votes

The change from SequenceIterator to Sequence was made in 9.5, and was part of a general tidy-up that included the introduction of the Sequence class to combine the previous Value and ValueRepresentation. There's a (short) explanation here: http://www.saxonica.com/documentation9.5/index.html#!changes/spi/9.4-9.5.1. While we try to minimize disruptive changes like this we generally take the view that when things are wrong and distorting the design of new features, we will put them right at the expense of backwards compatibility.

I'm not sure what release you are using now: the SingletonItem class existed in 9.5 but was gone by 9.6; if you're moving forward then I would suggest moving straight to 9.8.

Best practice is to do

NodeInfo dataNode = (NodeInfo) argument[0].head();

which will work regardless of the internal representation of the argument.