You'll need to drill up to the top controller with more $Up(s) or $Top depending on the Depth of the loop. You could probably also simplify the FirstXPO function to just retun the ID using SQLQuery instead of the whole objcet, but you get the idea. The other option is to add a method to the XPTO class to determine if its the first one. Either the XPTO xlass needs to know if it s first or the main page needs to know which is XPTO is first
True that works, though I'd be careful it may impact performance depending on how complex your DataObjects are since you're essentailly pulling the Children() multiple times. Once in the tempalte the and once in the getActiveTab function. Getting one XPTO record may be less overhead, I'm not sure if the Children() query is cached for the whole controller or just teh temaplte function.