Rick, I think I follow you, but I'm not 100% sure. Here is a revision to that function, that first gets the last sibling element in the selection, then walks down the last branch(es) to the furthest extent. If this is not what you are looking for, then I think it might be much more complicated than I understand. Also, by the way, FrameSLT does not support that XPath expression. I don't believe there is an equivalent, but I'd really have to think about it.
Also, you certainly understand this, but let me note for others that this function is missing lots of important error handling. It is only robust if the input is exactly as expected (ie, a valid document with a valid element selection).
Russ
function getLastSelectedElement(doc)
{
var er = doc.ElementSelection;
var lastElem;
var tempLastElem;
var elem = er.beg.child;
while(elem.ObjectValid() && elem.id != er.end.child.id)
{
//alert(elem.ElementDef.Name);
tempLastElem = elem;
elem = elem.NextSiblingElement;
}
while(tempLastElem.ObjectValid())
{
lastElem = tempLastElem;
tempLastElem = tempLastElem.LastChildElement;
}
return lastElem;
}