I was finally able to achieve my original goal, which was to convince Saxon that my function's results don't need to be sorted, but it took some fiddling with Saxon internal APIs. 

I created https://dev.saxonica.com/community/issues/1495 with a request to expose some methods to enable this in the public API.

-Mike


PS there is a broken link here: http://sourceforge.net/tracker/?group_id=29872&atid=397617 to http://dev.saxonica.com/redmine that you might want to patch up.

On 4/24/2012 3:31 AM, Michael Kay wrote:
I'd suggest using an operator that doesn't require sorting into document 
order:

(for $x in my:function("arg") return $x/descendant::element('':scene))[1]

or since you're already using 3.0 syntax:

(my:function("arg") ! descendant::element('':scene))[1]

Note that just because it's a sequence of document nodes doesn't in 
itself mean they don't need to be sorted. The sort order of document 
nodes might be arbitrary, but for use in operations like "|" which take 
two sorted sequences of nodes as input, the nodes have to be in 
predictable order.

Michael Kay
Saxonica

On 24/04/2012 02:26, Michael Sokolov wrote:
When Saxon compiles an expression of this form:

      (my:function("arg")/descendant::element(SCENE))[1]

it generates an internal expression like this:


firstItem(documentSort(my:function("arg")/descendant::element('':SCENE)))

my:function is an ExtensionFunction that is declared as returning a
sequence of nodes, although in fact it always returns only document
nodes, so documentSort shouldn't be needed, and I think a consequence of
its being there is that the function's result has to be completely
iterated, which I'd like to avoid since it is expensive.

Is there any way to indicate to Saxon that the result of an
ExtensionFunctionCall is already in document order and doesn't need to
be sorted?  If I specified document-node()* as the return type would
that help?  I'm a little bit unsure how to do that so I haven't tried
yet (there isn't a nice constant for that as there is for
SequenceType.NODE_SEQUENCE).

-Mike Sokolov

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help

------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and 
threat landscape has changed and how IT managers can respond. Discussions 
will include endpoint security, mobile security and the latest in malware 
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
saxon-help@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/saxon-help