saxon extension function with NODE_SEQUENCE or ANY_SEQUENCE

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



saxon extension function with NODE_SEQUENCE or ANY_SEQUENCE



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 Answer
1



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.


SequenceIterator


Sequence


Sequence


Value


ValueRepresentation



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.


SingletonItem



Best practice is to do


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



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





Hi Michael. Thanks, this does work for the NodeInfo. However, I still have the question regarding the returning value. How can I convert my ArrayList<String> to a sequence? I will switch to 9.8 as per your suggestion, since it seems reasonable, however, it did cause another compiling issue, but I assume a new post will be better (method setSource on XPathEvaluator didn't exist. Will make some searching before :) ).
– Fabien
Aug 13 at 7:59






Simplest is to convert the List<String> to a List<StringValue> by converting each string, then use SequenceExtent.makeSequenceExtent(List<T>).
– Michael Kay
Aug 13 at 16:24


List<String>


List<StringValue>


SequenceExtent.makeSequenceExtent(List<T>)






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard