External functions example

  • fcavalieri83

    I need to write an external function having a node sequence parameter and which returns a node sequence. Is it possible to write, for instance, a java external function which returns the union of the childs of the nodes given as parameter?
    Can you provide an example?


    Federico Cavalieri

  • Dear Federico,

    it is certainly possible to write external functions that work on a sequence of nodes and return a sequence of nodes - the iterators implementing the XQuery functionality are exactly written that way. You can have a look at the relevant iterators/functions for an example (ch.ethz.mxquery.iterators/ch.ethz.mxquery.functions.fn/xs/)

    MXQuery uses a token representation to implement XDM, so node  accessors are only available for the local content (name, type, node ID), not for the nested content (e.g. children, attributes). These need to be evaluated by collecting them.

    To fully understand what your are trying to achieve (and provide with a more detailed explanation), could you give more details on your desired function?

    Regarding your example query: Why not use a normal Child path expression with the an according node test, e.g. /node()?

    Peter Fischer