Regarding access to ancestor attributes in a streaming stylesheet:
 
How I solved my issue capturing ancestor information for use in this streaming stylesheet was to write another stylesheet that extracts only the top three levels of the hierarchy, producing a single file that then is used as a reference.  It is the input document instead of <stubs/> to the streaming stylesheet.  When constructing the collection-uri, I look up the table name in the reference document and then use it's parent to get the database name.