declare namespace tei="http://www.tei-c.org/ns/1.0"; declare variable $Chas as document-node() := doc('/db/mitford/literary/Charles1.xml'); declare variable $ChasPlay as element() := $Chas/*; declare variable $si as document-node() := doc('https://digitalmitford.org/si.xml'); declare variable $yStretchFactor := 10; declare variable $xStretchFactor := 75; Who is talked about the most in Mitford’s Charles the First? { let $Chaspersons := $Chas//tei:body//tei:persName let $TotPersonsCount := count($Chaspersons) let $siPersons := $si//tei:person let $ChasPersonRefs := $Chaspersons/@ref/string() let $distChPRs := sort(distinct-values($ChasPersonRefs)) let $countList := for $i in $distChPRs let $countInPlay := count($Chaspersons[@ref = $i]) let $percent := $countInPlay div $TotPersonsCount * 100 where $percent > 2 order by $percent descending return $i for $i at $pos in $countList let $siCPrs := $si//tei:person[@xml:id = substring-after($i, '#')] let $name := ($siCPrs/tei:persName)[1]/string() let $countInPlay := count($Chaspersons[@ref = $i]) let $percent := $countInPlay div $TotPersonsCount * 100 let $percentFormatted := format-number($percent, '#.#') let $XPos := ($pos * $xStretchFactor - ($xStretchFactor div 2)) let $YPos := -($percent * $yStretchFactor) let $height := $percent * $yStretchFactor let $width := 50 let $TextXPos := $XPos + $width div 2 return {$percentFormatted}% {$name} }