[xquery-talk] Collections - family relationships

David Lee dlee at calldei.com
Sun Jan 5 14:17:26 PST 2014

Not even knowing of the existence of fn:filter or fn:for-each-pair I wrote just now my version in old-fashioned-xquery

declare function common:node-index-of( $nodes as node()* , $node as node() ) as xs:integer ? 
   for $n at $pos in $nodes 
      if( $n is $node )
         then  $pos
      else  ()

Signature may have to change if the same node exists > 1 time in a sequence

fn:for-each-pair looks like a really useful function ! I am often brain-stumped trying to skip over every other node in a sequence having to write div 2 and  ($i div2) + 1 etc

David A. Lee
dlee at calldei.com

-----Original Message-----
From: Michael Kay [mailto:mike at saxonica.com] 
Sent: Sunday, January 05, 2014 4:48 PM
To: David Lee
Cc: ihe.onwuka at gmail.com; talk at x-query.com
Subject: Re: [xquery-talk] Collections - family relationships

On 5 Jan 2014, at 21:24, David Lee <dlee at calldei.com> wrote:

> Arg ... so your saying index-of causes a string atomization ?
> Ug.  I know it wants item*  and uses "eq" as the comparison but didn't realize that would stringify documents ... 

Actually the function signature for index-of expects xs:anyAtomicType, which means that if you supply a node it is atomized during the function call.
> Do you know of a sequence function that uses document or node ID's ? 

union, intersect, difference....

The function index-of-node() is given as an example of a function you can write yourself:


Generally the functions in this appendix were considered for inclusion in the spec, and rejected because they can easily be implemented as user-defined functions.

Michael Kay

More information about the talk mailing list