Manuel Collado wrote: > It would be nice to have uniform macro code that works for both simple > and multiple selections. It seems that predefined variables like > 'selected' and 'selected2' would be enough, but in fact they aren't: > > a.- 'selected2' is only meaningful for multiple selections. > b.- 'selected' and 'selected2' may not be in document order. > > The following code fragment is an attempt (after several ones) to locate > the first and last nodes, in document order, for any explicit selection: > > [1] <set variable="selectedNodes" expression="$selectedNodes" /> > [2] <set variable="firstSelected" expression="$selected" /> > [3] <choice> > <sequence> > <test context="$selected2" expression="." /> > <set variable="lastSelected" expression="$selected2" /> > </sequence> > <set variable="lastSelected" expression="$selected" /> > </choice> > > This code seems to work OK, but has some drawbacks: > > a.- It relies on an undocumented feature of [1]. Reselecting the current > selection as a whole lets 'selected' and 'selected2' to be in document > order. > b.- There is a clear assimetry for locating the first node [2] and the > last node [3] in the selection. >
You are right. I propose the following changes: [1] In a macro, $selected will always denote the first (in document order) selected node if any (i.e. otherwise, empty node set). [2] In a macro, $selected2 will always denote the last (in document order) selected node if any (i.e. otherwise, empty node set). Is that OK for you?

