I am interested in attaching the unique speaker labels to the character in the RDF rendering by getting distinct-values of the string value in <speaker>. I implemented this in the rdf.xqm which is probably not the best idea because this makes re-using this function much harder.
Consider adding a function to util.xqm:
let $distinct-speaker-labels := $play//tei:sp[@who eq "#" || $character-item?id]/tei:speaker/string() => for-each(function($label) { replace($label, '\.$', '') }) => distinct-values()
This results in normalizing "EMILIA" and EMILIA. to a unique value EMILIA, but includes "ODOARDO" and "ODOARDO GALOTTI" as distinct labels.
Consider setting up a range index on the sp[@who] attribute value to speed up the lookup of @who eq "#" || $character-item?id.