Michael Kay wrote:
 - how do I use the a NodeInfo as the context for the 
expressions to be evaluated (and reuse namespaces and variables, so.)
    

For run-time context, it's easy to set up the dynamic context in an
XPathContext object. Never modify the context you were supplied with on the
call, always create a new one (use the saxon:highest function for guidance).
As mentioned, static context is more difficult. This is why saxon:evaluate
doesn't give you access to the variables defined in the stylesheet, instead
it gives you access to its own set of variables $p1, $p2 etc which are bound
to extra parameters in the extension function call.
  
Things nearly seemed to work but I forgot that the data I receive often makes use of the default namespace which makes things brake:

So using "saxon:highest(/d:value, saxon:expression('number(d:number)') )" on (with "default" mapped to the prefix "d") throws an error:

<root xmlns="default">
    <ground>
        <value><number>9</number><char>a</char>9-a</value>
        <value><number>8</number><char>b</char>8-b</value>
        <value><number>7</number><char>c</char>7-c</value>
        <value><number>6</number><char>d</char>6-d</value>
        <value><number>5</number><char>e</char>5-e</value>
        <value><number>4</number><char>f</char>4-f</value>
        <value><number>3</number><char>g</char>3-g</value>
        <value><number>2</number><char>h</char>2-h</value>
        <value><number>1</number><char>i</char>1-i</value>
        <value><number>0</number><char>j</char>0-j</value>
        <level>
            <value><number>10</number><char>j</char>10-k</value>
            <value><number>11</number><char>j</char>11-l</value>
            <value><number>12</number><char>j</char>12-m</value>
            <value><number>13</number><char>j</char>13-n</value>
            <value><number>14</number><char>j</char>14-o</value>
            <value><number>19</number><char>j</char>19-t</value>
            <value><number>18</number><char>j</char>18-w</value>
            <value><number>17</number><char>j</char>17-r</value>
            <value><number>16</number><char>j</char>16-q</value>
            <value><number>15</number><char>j</char>15-p</value>
        </level>
    </ground>
</root>

Is it possible to create the expression (programmatically) at runtime, so that I could basically write something like "saxon:highest(/d:value, 'number(d:number)' )" or in my case "sort:sort-by(/d:value, 'number(d:number)' ) ?

Victor